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.
- Prepare
- Python
- Collections
- Company Logo
- Discussions
Company Logo
Company Logo
Sort by
recency
|
1308 Discussions
|
Please Login in order to post a comment
sorted() with reverse=True is reversing list completely! So you letters with same freq are on inverted order - changing freq to negative do the trick
from collections import Counter s=input() freq_let=Counter(s) for entry in freq_let.most_common(3): print(*entry)
In this question by using most_common makes the code very understandable and is less time taking....
u just calculate the words frequency convert them to list sort them alphabetically later sort them value based return the top three items