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=list(input())d={}forvins:ifvnotind:d[v]=1else:d[v]+=1# sort by value key first (alphabetical order), a through z d=dict(sorted(d.items(),key=lambdax:x[0]))# sort dictionary by key (occurrence), largest to smallestd=dict(sorted(d.items(),key=lambdax:x[1],reverse=True))# get first three outputs of the sorted dictionaryres={k:vfori,(k,v)inenumerate(d.items())ifi<3}forkey,valueinres.items():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 →
Extra challenge: do not use Counter