DefaultDict Tutorial

  • + 0 comments

    I was getting hung up on the addition of -1 untill I saw your example. I basically just merged what you had there into my flat for loop

    from collections import defaultdict
    n, m = map(int, raw_input().split())
    d = defaultdict(list)
    [d[raw_input()].append(i+1) for i in range(n)]
    for j in [' '.join(map(str, d[raw_input()])) or -1 for i in range(m)]: print j