• + 0 comments

    Did a little digging and found the Counter.most_common(n) method, which returns the list you need to iterate print(*) through. Sorted the string beforehand because .most_common(n) will sort by order of elements encountered.

    from collections import Counter
    
    
    if __name__ == '__main__':
        s = sorted(input())
        s_count = Counter(s)
        [print(*entry) for entry in s_count.most_common(3)]