我想通過以下條件從列表中過濾出一些令牌。 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)中的第一句告訴你如何工作與他們:「計數器是一個字典的子類」,如果你打算使用一個類或函數,你最好先閱讀它的文檔。 –