• + 6 comments

    Hi, my solution is very similar to yours. It just uses OrderedDict, which keeps the order of the pairs, when you print them.

    from collections import OrderedDict
    #define empty ordered dictionary, which counts occurences
    dict = OrderedDict()
    
    for i in range(int(input())):
        #If input not in the dictionary, then add it
        #else increment the counter
        key = input()
        if not key in dict.keys():
            dict.update({key : 1})
            continue
        dict[key] += 1
    
    print(len(dict.keys()))
    print(*dict.values())