【发布时间】:2016-05-21 12:16:51
【问题描述】:
我正在编写一个程序,它可以查找文本块中的每个单词并输出每个单词以及该单词被使用的次数。
我当前的代码在这里:
text = input("Please enter some text ")
terminator = len(text)
n = 0
word = ""
wordlist = []
while len(text) > 0:
if word != "":
wordlist.append(word)
text = text[n:]
word = ""
n = 0
for char in text:
if char != " ":
word = word + char
n = n + 1
else:
text = text[1:]
break
for item in wordlist:
print(item)
谢谢:)
【问题讨论】:
-
看起来像是
collections.Counter的工作。 . .
标签: python arrays text char words