可以先使用collections库中的Counter函数统计每个单词中出现的字母数量,然后使用sorted函数将字典按照value值(即字母数量)降序排序,最后返回一个列表包含每个单词的字母数量降序排列。
示例代码:
from collections import Counter
def sort_letter_count(words): counter = Counter(words) sorted_counter = sorted(counter.items(), key=lambda x: x[1], reverse=True) return [x[1] for x in sorted_counter]
上一篇:按字母筛选的列表报告
下一篇:按字母顺序编号div