题目:
我的解法:
1 def checkio(text): 2 import string 3 str = text.encode().lower() 4 adict = {} 5 for i in string.lowercase[::-1]: 6 if (str.count(i) > 0 ): 7 adict[i] = str.count(i) 8 tmp = max(adict.values()) 9 tmpch = 'z'10 for x in adict:11 if tmp == adict[x]:12 print x13 if tmpch > x:14 print x15 tmpch = x16 return tmpch
感觉还不错的解法:
1 def checkio(s):2 s = s.lower()3 l = list(set((x,s.count(x)) for x in s if x.islower()))4 l.sort(key = lambda x: (-x[1],x[0]))5 return l[0][0]