• + 2 comments

    I haven't checked in python2 - but in 3 you don't need defaultdict if you use Counter.

    from collections import Counter, defaultdict
    
    cnt = Counter([input().strip() for _ in range(int(input().strip()))]) 
    
    for _ in range(int(input().strip())):
        print(cnt[input().strip()])