DefaultDict Tutorial

  • + 0 comments

    from collections import defaultdict

    n, m = map(int, input().split())

    d = defaultdict(list)

    for i in range(1, n+1): word = input() d[word].append(i)

    for j in range(1, m+1): word = input()
    print(* d[word] if d[word] else [-1])