DefaultDict Tutorial

  • + 0 comments
    from collections import defaultdict
    n,m = map(int,input().split())
    d = defaultdict(list)
    for i in range(n):
        A = input()
        d[A].append(i+1)
    
    for j in range(m):
        B = input()
        if B in d.keys():
            val = d[B]
            print(*val)
        else:
            print(-1)