DefaultDict Tutorial

  • + 1 comment

    What's wrong with below code, why all the test cases are not passing.

    from collections import defaultdict

    d=defaultdict(list)

    A = ['a','b','a','b']

    B= ['c']

    for i in B:

    if i in A:
    
        for index,j in enumerate(A):
    
            if i==j:
    
                d[i].append(index+1)
    
    else:
    
        d[i].append(int(-1))
    

    for values in d.values():

    print(*values)