python - 有没有办法用 python 检查列表中的字符串是否是常用英语中使用的真实单词?
问题描述
我正在尝试从关键字列表中提取仅是英语中常规正常单词的单词。
这是我的代码:
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']
推荐阅读
- racket - Racket - 递归合约
- hiredis - 从hiredis(C编程中的Redis客户端)存储和检索字典数据
- r - 无法正确打开 html IOSlides 输出
- java - 如何以 XML 样式使用 MyBatis-SpringBoot-MySQL 执行正确的 SQL INSERT?
- ios - 数组在错误的位置返回值
- javascript - 为什么javascript将这些变量作为php中的对象?
- javascript - 如何在 JavaScript 中订阅 OpenLayers 5.3.0 事件?
- elasticsearch - 使用弹性搜索查询过滤和匹配
- database - 如何解决 Airflow Scheduler 中的数据库连接无效警告?
- pyspark - 将一列 DenseMatrices 拆分为单独的行(每行有一个向量)