• + 0 comments

    I have just started learning and I was not aware of Counter Class and the method most_common()

    Glad I came accross Boki's solution from 9 years back! Classes are a bit tough to understand though so I made something of my own.

    from collections import Counter
    
    
    if __name__ == '__main__':
        
        # sorting alphabetically so they occur in alphabetic order
        company_name = sorted(input())
        
        # count 3 most common characters
        three_most_common_chars = Counter(company_name).most_common(3)
        
        for char, freq in three_most_common_chars:
            print(f"{char} {freq}")
        
        for char, freq in three_most_common_chars:
            print(f"{char} {freq}")