我试图从关键字列表中仅提取英语中的常规普通词。
这是我的代码:
words = ['apple','a%32','j & quod','rectangle','house','fsdfdsoij','fdfd']
for word in words:
if word ???: # How can I check if the words is a real word? Any module that I can use for that or a free API?
print:
else:
pass
我只想得到结果:
apple
rectangle
house
第一步,安装nltk
然后:
import nltk
nltk.download('words')
from nltk.corpus import words
samplewords=['apple','a%32','j & quod','rectangle','house','fsdfdsoij','fdfd']
[i for i in samplewords if i in words.words()]
['apple', 'rectangle', 'house']
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句