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
|
1123 Discussions
|
Please Login in order to post a comment
from collections import defaultdict
if name == 'main':
N = list(map(int, input().split())) d = defaultdict(list) for i in range(N[0]): letter = input() d[letter].append(int(i+1)) #print(d)
purchase_order(arr, sizes)
This code passes half the test cases but fails the other half. Any ideas on why?
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])