首页 > 其他 > 详细

most-wanted-letter

时间:2015-04-09 21:33:48      阅读:126      评论:0      收藏:0      [点我收藏+]

题目:

技术分享

我的解法:

 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]

 

most-wanted-letter

原文:http://www.cnblogs.com/canxuexiecheng/p/4411075.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!