小编Adi*_*dge的帖子

一行 for 循环将元素添加到 Python 中的列表

我正在尝试从我的数据集中删除停用词(来自 nltk),但不确定为什么单行查询不起作用:

filtered_words = [word if word not in stop_words for word in words]
Run Code Online (Sandbox Code Playgroud)

这是我需要做的:

filtered_words = []
for word in words:
    if word not in stop_words:
        filtered_words.append(word)
Run Code Online (Sandbox Code Playgroud)

python for-loop

3
推荐指数
1
解决办法
8019
查看次数

标签 统计

for-loop ×1

python ×1