我有一个单词/用具的清单
appliances = ['tv', 'radio', 'oven', 'speaker']
我还有一个句子,我已经标记了
sent = ['We have a radio in the Kitchen']
sent1 = word_tokenize[sent]
我想说,如果电器是在sent1然后打印是,否则打印否。我做了下面的,但不断得到作为打印否
if any(appliances) in sent1:
print ('yes')
else:
print ('no')
有没有更好的办法
Tags:
试试这样的
根据@tobias\u k评论编辑
使用惰性评估
编辑:基于@ben121评论
如果你想看看你的句子里有没有电器,你可以这样做
相关问题 更多 >
编程相关推荐