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] + 1
for word_count in zip(diff_words,counts):
print(word_count)