most-wanted-letter

题目:

我的解法:

 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 x
13             if tmpch > x:
14                 print x
15                 tmpch = x
16     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]

 

posted @ 2015-04-09 19:23  小名辉辉  阅读(209)  评论(0编辑  收藏  举报