You are viewing a single comment's thread. Return to all comments →
Using Walrus Operator
from collections import defaultdict
n,m = map(int,input().split())
a = defaultdict(list)
for i in range(n): a[input()].append(i+1)
for i in range(m): print(*a[x] if (x:=input()) in a else [-1])
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
DefaultDict Tutorial
You are viewing a single comment's thread. Return to all comments →
Using Walrus Operator
from collections import defaultdict
n,m = map(int,input().split())
a = defaultdict(list)
for i in range(n): a[input()].append(i+1)
for i in range(m): print(*a[x] if (x:=input()) in a else [-1])