Light Mode
Dark Mode
got stuck on sort a dict

import re

def checkio(text):

    text = text.lower()
    list1 = re.findall(r'[a-zA-Z]',text)
    set1 = set(list1)
    times = []
    for i in set1:
        times.append(list1.count(i))
    d = dict(zip(set1,times))
    d1 = sorted(d.items(),key = lambda x: (-x[1], x[0])) 
    return d1[0][0]

I finally solved this after i saw the hints. but i can't figure out the code to sort a dict here :

sorted(d.items(),key = lambda x: (-x[1], x[0]))

could anyone kindly send some explanations or guides to me?

Created: March 9, 2016, 7:52 a.m.
Updated: Oct. 21, 2019, 8:20 a.m.
0
13
User avatar
geniuscc78