我想通过以下条件从列表中过滤出一些令牌。 1)令牌长度大于5 2)出现的频率(在原文)超过100通过多个条件从列表中过滤令牌
我用下面的代码
#token_list is a list object containing tokenized words from raw text
from collections import Counter
c = Counter(token_list)
selected_tokens = [word for word in token_list if len(word) > 5 and c.item[2] > 100]
selected_tokens
,但似乎无法得到它。我相信错误来自'c.item [2]',但不太了解'Counter()'命令背后的机制。
如果有人能够启发我,我会非常感激。
谢谢。
字面上[Counter'documentation](https://docs.python.org/3/library/collections.html#collections.Counter)中的第一句告诉你如何工作与他们:“计数器是一个字典的子类”,如果你打算使用一个类或函数,你最好先阅读它的文档。 –