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.
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)
Cookie support is required to access HackerRank
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 →
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)