单词多久出现在列表中-Python
我有一个单词列表。 我想出了如何计算每个单词的发生。 我现在想知道在该列表中出现了多少次(?)。输出应该看起来像这样:
4.500单词出现1次
6.000单词2次 ...
示例:
list = ["hello", "time", "burger", "hello", "mouse", "time", "time"]
预期输出:
3 Word occurred 1 time
1 Word orrcured 2 time
1 Word occurred 3 time
我希望我的意思是我的意思。我无法共享代码,因为我不知道该怎么做。
是否有可以做到这一点的内置功能?
还是有人有一种平稳的计算方式?
多谢 !
I have a list of words.
I figgured out how to count the occurrence of each word.
I now want to know how many words appear how many times(?) in that list. The output should look something like this:
4.500 Words appeard 1 time
6.000 Words appeard 2 time
...
Example:
list = ["hello", "time", "burger", "hello", "mouse", "time", "time"]
Expected output:
3 Word occurred 1 time
1 Word orrcured 2 time
1 Word occurred 3 time
I hope it is clear what I mean to do. I cant share code really since I have no clue how to do it.
Is there an inbuilt function with Counter or Pandas that can do this?
Or does anyone have a smooth way of computing this ?
THANKS A LOT !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的;使用
计数器
来计算每个单词出现的次数,然后在该计数器上使用counter
来计数每次出现多少个单词。请注意,
word_counts
给出每个单词的计数,然后count_counts
给出word_counts
:Yes; use a
Counter
to count the number of times each word appears, and then use aCounter
on that counter to count how many words appear each number of times.Note that
word_counts
gives the counts per word, and thencount_counts
gives the counts per count inword_counts
:如果您知道如何计算每个单词的发生,则该过程很简单。在伪代码中:
a = n*[0]
,其中n是每个单词的单词量m
是单词发生的次数。然后doa [m] ++
print(str(a [i]) +“ shops epply” + str“ + str(i) +“ times”)
If you know how to count the occurrences of each word, the procedure is straightforward. In pseudo-code:
A = n*[0]
, where n is the amount of wordsm
be the number of times the word occurs. Then doA[m]++
print(str(A[i]) + " words appear " + str(i) + "times")