You are viewing a single comment's thread. Return to all comments →
Setting the default value to -1 rather than to a list as you suggested:
from collections import defaultdict n, m = map(int, input().split()) d = defaultdict(lambda: -1) for i in range(1, n+1): word = input() d[word] = d[word] + ' ' + str(i) if word in d else str(i) for _ in range(m): print(d[input()])
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 →
Setting the default value to -1 rather than to a list as you suggested: