DefaultDict Tutorial

  • + 0 comments

    if u want u can create a defaultdict which creates an empty list for all the values it get's from group a and append the indeces of those values or u create ur own dictionary append the indeces of the list a and check with list b and print the indeces of each element.

    d={}
    for i in range(1,n+1):
        w=input()
        if w not in d:
            d[w]=[]
        d[w].append(str(i))
    
    for _ in range(m):
        y=input()
        if y in d:
            print(' '.join(d[y]))
        else:
            print(-1)