代码
"""
功能:统计单词个数
作者:温胡可
时间:2021.11.25
"""
text = 'I love python very much'
# 拆分
words = text.split(' ')
# 去重
diff_words = list(set(words))
# 统计单词列表
counts = []
for i in range(len(words)):
counts.append(0)
# 统计各单词个数
for i in range(len(words)):
for j in range(len(diff_words)):
if words[i] == diff_words[j]:
counts[j] = counts[j] + 1
# 输出结果
for word_count in zip(diff_words, counts):
print(word_count)