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
|
1066 Discussions
|
Please Login in order to post a comment
Can i use this on [fmwhsapp.com](https://fmwhsapp.com/ ) blog?
Specify that the default value is provided by a factory function when the defaultdict is created. online cricket id
from collections import defaultdict
n, m = list(map(int,input().split())) Groups = defaultdict(list)
for i in range(n): Groups['A'].append(input())
for i in range(m): Groups['B'].append(input())
for word in Groups['B']: indices = [] for i, each in enumerate(Groups['A']): if word == each: indices.append(i+1) if indices: print(*indices) else: print(-1)