• + 0 comments

    Is better solution using Counter (as i learnt from other posting), anyway here is my solution.

    from itertools import groupby

    if name == 'main':

    s = sorted(list(input()))
    
    cap= [(k, len(list(g))) for k, g in groupby(s) ]
    
    print (cap)
    res = sorted(cap, reverse=True, key=lambda qty: qty[1])
    

    for x in range(3):
    print(res[x][0],res[x][1] )