- Python编程300例:快速构建可执行高质量代码
- 李永华编著
- 161字
- 2021-03-26 23:33:20
例51 最高频的k个单词
1.问题描述
给一个单词列表,求出这个列表中出现频次最高的k个单词。
2.问题示例
输入:
[ "yes","long","code", "yes","code","baby", "you","baby","chrome", "safari","long","code", "body","long","code" ] k=3
输出:["code","long","baby"]
输入:
[ "yes","long","code", "yes","code","baby", "you","baby","chrome", "safari","long","code", "body","long","code" ] k=4
输出:["code","long","baby","yes"]
3.代码实现
4.运行结果
输入:['yes','long','code','yes','code','baby','you','baby','chrome','safari','long','code','body','long','code']
输入:k=4
输出:['code','long','yes','baby']