You are viewing a single comment's thread. Return to all comments →
from collections import defaultdict d = defaultdict(str) n,m = map(int,input().split()) for i in range(n): d[input()]+=f'{i+1} ' for i in range(m): print(d.get(input(),-1))
.get() allows a simple way to print the value or -1 and avoids creating new values in defaultdict
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 →
.get() allows a simple way to print the value or -1 and avoids creating new values in defaultdict