You are viewing a single comment's thread. Return to all comments →
from collections import defaultdict
n, m = map(int, input().split())
groupA = defaultdict(list) for i in range(1, n + 1): word = input().strip() groupA[word].append(i)
groupB = [input().strip() for _ in range(m)]
for word in groupB: if word in groupA: print(*groupA[word]) else: print(-1)
Seems like cookies are disabled on this browser, please enable them to open this website
DefaultDict Tutorial
You are viewing a single comment's thread. Return to all comments →
from collections import defaultdict
n, m = map(int, input().split())
groupA = defaultdict(list) for i in range(1, n + 1): word = input().strip() groupA[word].append(i)
groupB = [input().strip() for _ in range(m)]
for word in groupB: if word in groupA: print(*groupA[word]) else: print(-1)