DefaultDict Tutorial

  • + 0 comments
    from collections import defaultdict
    
    n, m = list(map(int, input().split()))
    list1 = []
    
    d = defaultdict(list)
    for i in range(n):
        d[input()].append(i+1)
    for _ in range(m):
        list1.append(input())
    for i in list1:
        if i in d:
            print(" ".join(map(str, d[i])))
        else:
            print(-1)