DefaultDict Tutorial

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