We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Collections
- DefaultDict Tutorial
- Discussions
DefaultDict Tutorial
DefaultDict Tutorial
Sort by
recency
|
1121 Discussions
|
Please Login in order to post a comment
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])
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)