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.
from collections import defaultdict
size_of_groups = input().split(' ')
A=[]
result= defaultdict(list)
for i in range(int(size_of_groups[0])):
A.append(input())
for i in range(int(size_of_groups[1])):
x=input()
if x not in A :
result[x].append(-1)
while x in A :
result[x].append(A.index(x)+1)
A[A.index(x)]= 0
for i in result.values():
print(' '.join(str(x) for x in i))
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 →
test 1 ,2 and 5 did not pass please help.
from collections import defaultdict size_of_groups = input().split(' ') A=[] result= defaultdict(list) for i in range(int(size_of_groups[0])): A.append(input()) for i in range(int(size_of_groups[1])): x=input() if x not in A : result[x].append(-1) while x in A : result[x].append(A.index(x)+1) A[A.index(x)]= 0
for i in result.values(): print(' '.join(str(x) for x in i))