You are viewing a single comment's thread. Return to all comments →
from collections import defaultdict
n=input() n,m=map(int,n.split()) d=defaultdict(list) for i in range(n): word=input() d[word].append(i+1)
for i in range(m): word=input().strip() if word in d: ans=d[word] ans=map(str,ans) newans=" ".join(ans) print(newans) 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=input() n,m=map(int,n.split()) d=defaultdict(list) for i in range(n): word=input() d[word].append(i+1)
for i in range(m): word=input().strip() if word in d: ans=d[word] ans=map(str,ans) newans=" ".join(ans) print(newans) else: print(-1)