You are viewing a single comment's thread. Return to all comments →
Why my code doesn't work?
from collections import Counter string = sorted(Counter(input()).most_common(3), key= lambda x: (-x[1],x[0])) print("\n".join(x[0]+" "+str(x[1]) for x in string))
but this code is working
from collections import Counter string = sorted(Counter(input()).items(), key= lambda x: (-x[1],x[0]))[:3] print("\n".join(x[0]+" "+str(x[1]) for x in string))
Why if I used most_common, I get wrong answer?
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 →
Why my code doesn't work?
but this code is working
Why if I used most_common, I get wrong answer?