利用Collections模块的Counter来进行词频统计
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)):