python计算字母出现次数
时间:2020-08-04 16:43:29
收藏:0
阅读:81
pyschools 上面的题目:给定一个单词,输出字母及字母出现次数
python真是方便,可以一行代码搞定
def countLetters(word): return dict(sorted([(l,word.count(l)) for l in set(word)])) print(countLetters(‘google‘)) {‘e‘: 1, ‘g‘: 2, ‘l‘: 1, ‘o‘: 2}
评论(0)