我有一张单子
List = ['iamcool', 'Noyouarenot']
stopwords=['iamcool']
我要做的是从我的列表中删除stowprds。我试着用下面的脚本来实现这一点
query1=List.split()
resultwords = [word for word in query1 if word not in stopwords]
result = ' '.join(resultwords)
return result
所以我的结果应该是
result =['Noyouarenot']
我收到一个错误
AttributeError: 'list' object has no attribute 'split'
这也是对的,我少了什么小东西,请帮忙。我感谢你的帮助。你知道吗
具有检查
stopwords
中成员资格条件的列表理解。你知道吗或
filter
或者
set
操作,你可以参考我关于速度差异的答案here。你知道吗输出->;
['Noyouarenot']
下面是修复错误的片段:
另一种可能的解决方案是假设您的输入列表和非索引词列表不关心顺序和重复项:
相关问题 更多 >
编程相关推荐