DefaultDict Tutorial

  • + 0 comments

    from collections import defaultdict

    n, m = list(map(int,input().split())) Groups = defaultdict(list)

    for i in range(n): Groups['A'].append(input())

    for i in range(m): Groups['B'].append(input())

    for word in Groups['B']: indices = [] for i, each in enumerate(Groups['A']): if word == each: indices.append(i+1) if indices: print(*indices) else: print(-1)