给定一个单词,输出字母及字母出现次数

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}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-10-24
  • 2021-08-31
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
猜你喜欢
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
相关资源
相似解决方案