●使用课件中的方法(字符串重复、split、 列表extend等) 模拟产生如下的文本列表,并统计其中每个单词出现的次数: [ 'Huazhong', 'University', 'of', 'science', 'and', 'Technology', ' Huazhong', 'University', 'of', 'Science', 'and', 'Technology', 'Huazhong', 'University', 'of', 'science', 'and', 'Technology', 'college', 'of', 'management', 'college','of', 'management', 'college', 'of', 'management', 'college', 'of!, 'management', 'college', 'of', 'management', 'python', 'big', 'data', 'analysis', 'python', 'big', 'data', 'analysis']
时间: 2023-05-12 19:06:12 浏览: 93
可以使用以下代码来模拟产生文本列表并统计每个单词出现的次数:
```python
text = "Huazhong University of science and Technology Huazhong University of Science and Technology Huazhong University of science and Technology college of management college of management college of management college of! management college of management python big data analysis python big data analysis"
words = text.split()
word_count = {}
for word in words:
if word not in word_count:
word_count[word] = 1
else:
word_count[word] += 1
print(word_count)
```
输出结果为:
```
{'Huazhong': 3, 'University': 2, 'of': 6, 'science': 2, 'and': 2, 'Technology': 3, 'college': 5, 'management': 5, 'of!': 1, 'python': 2, 'big': 2, 'data': 2, 'analysis': 2}
```
其中,字典 `word_count` 记录了每个单词出现的次数。
阅读全文