标记化句子中列表中的单词

word in list in tokenized sentence

我有单词/器具列表

appliances = ['tv', 'radio', 'oven', 'speaker']

我也有一句话,我分词了。

sent = ['We have a radio in the Kitchen']
sent1 = word_tokenize[sent]

我想说的是,如果设备在 sent1 中,则打印 yes,否则打印 no。我做了下面的事情,但一直没有打印出来。

if any(appliances) in sent1:
    print ('yes')
else:
    print ('no')

有更好的方法吗?

尝试这样的事情。

appliances = ['tv', 'radio', 'oven', 'speaker']
sent = ['We have a radio in the Kitchen']
sent1 = list(sent[0].split())

if any([app in sent1 for app in appliances]):
    print ('yes')
else:
    print ('no')

根据@tobias_k 评论编辑

使用惰性求值。

if any(app in sent1 for app in appliances):
    print ('yes')
else:
    print ('no')

编辑:基于@ben121 评论

如果你想在你的句子中看到 with appliance are 你可以这样做。

[app for app in appliances if app in sent1]