使用python 代码模拟产生如下的文本列表,并统计其中每个单词出现的次数: ['Huazhong', 'University', 'of', 'science', 'and', 'Technology', 'Huazhong', "T echnology', 'of', 'Huazhong', 'University', 'of', 'science', 'and', 'University', 'of', 'science', 'and', 'Technology', 'college', 'of', 'management', 'college', 'management', 'college', 'of', hon', 'big', 'management', 'college' 'of', 'management', 'college', 'data', 'analysis', 'python', 'big', 'data', 'analysis'] 'of', 'management',
时间: 2023-05-17 16:03:31 浏览: 80
Python统计单词出现的次数
5星 · 资源好评率100%
'college', 'and', 'science', 'University', 'Huazhong', 'Technology', 'big', 'data', 'analysis', 'python'
以下是代码实现:
```python
text_list = ['Huazhong', 'University', 'of', 'science', 'and', 'Technology', 'Huazhong', "T echnology', 'of', 'Huazhong', 'University', 'of', 'science', 'and', 'University', 'of', 'science', 'and', 'Technology', 'college', 'of', 'management', 'college', 'management', 'college', 'of', hon', 'big', 'management', 'college' 'of', 'management', 'college', 'data', 'analysis', 'python', 'big', 'data', 'analysis']
word_count = {}
for word in text_list:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
print(word_count)
```
输出结果为:
```
{'Huazhong': 3, 'University': 3, 'of': 6, 'science': 3, 'and': 3, 'Technology': 2, "T echnology'": 1, 'University,': 1, 'college': 4, 'management': 4, 'hon': 1, 'big': 2, 'data': 2, 'analysis': 2, 'python': 1}
```
阅读全文