编写一个读取单词列表的程序。然后,程序输出这些单词及其频率。
例如:如果输入是:
hey hi Mark hi mark
输出为:
hey 1
hi 2
Mark 1
hi 2
mark 1
这是我尝试过的:
list = 'hey hi Mark hi mark'
text = list.split()
for word in text:
freq = text.count(word)
print(*text, freq)
编写一个读取单词列表的程序。然后,程序输出这些单词及其频率。
例如:如果输入是:
hey hi Mark hi mark
输出为:
hey 1
hi 2
Mark 1
hi 2
mark 1
这是我尝试过的:
list = 'hey hi Mark hi mark'
text = list.split()
for word in text:
freq = text.count(word)
print(*text, freq)
The
Counter
class is useful for stuff like this:要么:
您只需要更换
至
您只想打印单词,而不是全文