给定一个单词,输出字母及字母出现次数
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}
给定一个单词,输出字母及字母出现次数
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}