We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
fromcollectionsimportCounterif__name__=='__main__':# sorting alphabetically so they occur in alphabetic ordercompany_name=sorted(input())# count 3 most common charactersthree_most_common_chars=Counter(company_name).most_common(3)forchar,freqinthree_most_common_chars:print(f"{char} {freq}")forchar,freqinthree_most_common_chars:print(f"{char} {freq}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Company Logo
You are viewing a single comment's thread. Return to all 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.