I have list of tuple and list. Need to return that not matched from the list.
listTuple = [('IN', 'OS19014'), ('CA', 'OS0001'), ('GB', 'OS0002'), ('CA', 'OS0003')] normalList = ['OS19014', 'OS0001', 'OS0002']
expected_result = [('CA', 'OS0003')]
CodePudding user response:
Try this:
>>> [lt for lt in listTuple if not lt[1] in set(normalList)]
[('CA', 'OS0003')]
CodePudding user response:
this code work for me:
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)