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.
s = input().lower()
# Create dictionary of each char count
dict = {char: s.count(char) for char in s}
# Return list of tuples by value count in descending order, and alphabetic for equal values
sorted_list = sorted(dict.items(), key = lambda x: (-x[1], x[0]))
# Print top three values of sorted_list
for key, value in sorted_list[:3]:
print(key, value)
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 did this: