Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Finding missing element in a list in Python

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading