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.
if name == 'main':
s = input().strip()
c = Counter(s)
# Sort by (-frequency, alphabetical)
top_3 = sorted(c.items(), key=lambda x: (-x[1], x[0]))[:3]
for char, freq in top_3:
print(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 →
if name == 'main': s = input().strip() c = Counter(s) # Sort by (-frequency, alphabetical) top_3 = sorted(c.items(), key=lambda x: (-x[1], x[0]))[:3] for char, freq in top_3: print(char, freq)