给定以下列表
['Jellicle', 'Cats', 'are', 'black', 'and', 'white,', 'Jellicle', 'Cats',
'are', 'rather', 'small;', 'Jellicle', 'Cats', 'are', 'merry', 'and',
'bright,', 'And', 'pleasant', 'to', 'hear', 'when', 'they', 'caterwaul.',
'Jellicle', 'Cats', 'have', 'cheerful', 'faces,', 'Jellicle', 'Cats',
'have', 'bright', 'black', 'eyes;', 'They', 'like', 'to', 'practise',
'their', 'airs', 'and', 'graces', 'And', 'wait', 'for', 'the', 'Jellicle',
'Moon', 'to', 'rise.', '']
我想要统计每个单词出现的次数,并显示前三个。
然而,我只希望找到首字母大写的前三个单词,并忽略所有首字母不大写的单词。
我相信还有更好的方法,但我的想法是:
- 将列表中的第一个单词放入另一个名为uniquewords的列表中
- 删除原始列表中第一个单词及其重复项
- 将新的第一个单词添加到unique words中
- 从原始列表中删除第一个单词及其重复项
- 等等...
- 直到原始列表为空为止...
- 计算uniquewords中每个单词在原始列表中出现的次数
- 找到前三个并打印
statistics.mode
)无法解决此问题。 - user202729