DefaultDict Tutorial

  • + 0 comments
    from collections import defaultdict
    
    size_A, size_B = map(int, input().split())
    
    occurrences: dict[str, list[int]] = defaultdict(list)
    
    for i in range(size_A):
        word_A = input()
        occurrences[word_A].append(i + 1)
    
    for _ in range(size_B):
        word_B = input()
        if word_B in occurrences:
            print(*occurrences[word_B])
        else:
            print(-1)