【发布时间】:2019-10-21 15:05:15
【问题描述】:
我有一个单词/设备列表
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')
有更好的方法吗?
【问题讨论】:
-
@JerryM。
any返回一个布尔值