1.编写程序 - 词频统计
‘’’
功能:词频统计
时间:2021年11月25日
‘’’
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)
2.检索子串出现次数
text = ‘I love python I love java I learn python’
words = text.split(’ ‘)
words.count(‘love’)
2
words.count(‘I’)
3