I have two lists J2 and J10. I am trying to find the elements in J10 which are absent in J2 but I am getting an error. I present the expected output.
J2=[128, 4, 6, 7, 8, 9, 10]
J10=[4, 6, 7, 8, 9, 10, 13, 128]
J=[i for i in J10 not in J2]
print(J)
The error is
in <module>
J=[i for i in J10 not in J2]
TypeError: 'bool' object is not iterable
The expected output is
[13]
>Solution :
J=[i for i in J10 if i not in J2]
Or:
lst=[]
for i in J10:
if i not in J2:
lst.append(i)
#[13]
Or
set(J10)-(set(J2))