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

How to remove all elements in a list that appear more than once

My question is different from removing duplicate

removing duplicate:

list_1 = [1, 2, 3, 4, 4, 3, 3, 7]

will become
you only keep one of the duplicated values

list_1 = [1, 2, 3, 4, 7]

My Question:

list_1 = [1, 2, 3, 4, 4, 3, 3, 7]

will become
you don’t keep any of the duplicated values

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

list_1 = [1, 2, 7]

>Solution :

The following will work:

list_1 = [1, 2, 3, 4, 4, 3, 3, 7]
res = [i for i in list_1 if list_1.count(i) == 1]

>>>print(res)
[1, 2, 7]
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