将元组列表与不匹配的列表和 return 列表进行比较

Compare list of tuples with list and return list of tuple that not matched

我有元组列表和第二个列表。我需要 return 一个元组列表,其中元组中的第二项没有出现在第二个列表中。

listTuple =  [('IN', 'OS19014'), ('CA', 'OS0001'), ('GB', 'OS0002'), ('CA', 'OS0003')]
normalList = ['OS19014', 'OS0001', 'OS0002']

Expected_result:

[('CA', 'OS0003')]

试试这个:

>>> [lt for lt in listTuple if not lt[1] in set(normalList)]
[('CA', 'OS0003')]

这段代码对我有用:

listTuple = [('IN', 'OS19014'), ('CA', 'OS0001'), ('GB', 'OS0002'), ('CA', 'OS0003')] 
normalList = ['OS19014', 'OS0001', 'OS0002']
for i in listTuple:
    if i[1] not in normalList:
        print(i)