DefaultDict Tutorial

  • + 0 comments
    1. from collections import defaultdict
    2. n,m = map(int,input().split())
    3. d = defaultdict(list)
    4. for i in range(n):
    5. z = input()
    6. d[z].append(i+1)
    7. for j in range(m):
    8. j = input()
    9. if j in d:
    10. print(*d[j])
    11. else:
    12. print(-1)