"""
python词频统计
"""
text = 'i love python i love java i learn python'
words = text.split(' ')
diff_words = list(set(words))
counts = []
for i in range(len(diff_words)):
counts.append(0)
for i in range (len(words)):
for j in range(len(diff_words)):
if diff_words[j] == words[i]:
counts[j] = counts[j] + i
for word_count in zip(diff_words, counts):
print(word_count)
Python词频统计(去重)
最新推荐文章于 2022-02-09 21:29:41 发布