python 一袋字

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 一袋字相关的知识,希望对你有一定的参考价值。

from nltk import word_tokenize
from collections import Counter
from nltk.corpus import stopwords

text = "Dennis is a great guy to work and live with!"

# Primary solution
tokens = word_tokenize(text)

# Use list comprehension to put everything to lower case
tokens = [w for w in word_tokenize(text.lower())]

# Use list comprehension to remove stopwords
no_stop = [t for t in tokens if t not in stopwords.words('dutch')]

BoW = Counter(no_stop)
print(BoW)
print(BoW.most_common(2))

以上是关于python 一袋字的主要内容,如果未能解决你的问题,请参考以下文章

Pig - 如何迭代一袋地图

Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

网易2017校招编程题

使用 pig,如何将混合格式的行解析为元组和一袋元组?

Python有有序集吗?

Python---解包