我认为你需要:l1 = [('is', 'VBZ'), ('plant', 'NN')]print([x for x in l1 if 'VB' in x[1]])输出[('is', 'VBZ')]为什么您的代码不起作用你正在检查是否VB在里面('is', 'VBZ'),它不在。据我了解,这些是POS tags并且将始终处于第一索引。您需要检查VB列表中每个元组的索引 1 是否存在
在您的解决方案中,您要检查子字符串,为此您需要搜索Tuple 中的元素。如果您想搜索确切的字符串,那么您的解决方案是正确的'VBZ' in ('is', 'VBZ')==> True'VB' in ('is', 'VBZ')==> False如果你知道exatly 2个元素将在元组中[tu for tu in l1 if 'VB' in (tu[1] or tu[0])] ==> [('is', 'VBZ')]如果您不确定元组中的元素[tu for tu in l1 if any(['VB' in elem for elem in tu])] ==> [('is', 'VBZ')]