按python中的字母频率对列表进行排序(降序)

Nee*_*imo 5 python frequency

就像标题说的那样,我需要编写一个按字母频率对列表进行排序的函数.通常我会提供我的代码到目前为止,但我不知道从哪里开始.我确信这很简单,但我不知道该怎么办.我需要按降序排序,感谢任何帮助.

rob*_*ing 9

在python 2.7或更高版本中,您可以使用计数器:http: //docs.python.org/dev/library/collections.html#collections.Counter

>>> mywords = ['red', 'blue', 'red', 'green', 'blue', 'blue']
>>> cnt = Counter(mywords)
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1})
Run Code Online (Sandbox Code Playgroud)

按照使用python的Sorted Word频率计数

如果你需要字母而不是单词,你可以这样:

>>> mywords = ['red', 'blue', 'red', 'green', 'blue', 'blue']
>>> myletters=list("".join(mywords))
>>> myletters
['r', 'e', 'd', 'b', 'l', 'u', 'e', 'r', 'e', 'd', 'g', 'r', 'e', 'e', 'n', 'b', 'l', 'u', 'e', 'b', 'l', 'u', 'e']
>>> Counter(myletters)
Run Code Online (Sandbox Code Playgroud)