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

Python – Compare list element if exist

I have a large table couple of millions of pairs of ints [[1,2],[45,101],[22,222] etc..].
What is the quickest way in Python to remove duplicates ?

Creating empty list and appending it "if not in" doesn’t work since it takes ages. Converting to Numpy and use "isin" I can’t seem to get it to work on pairs.

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

>Solution :

you can do the following

arr = [[1,2],[45,101],[22,222], [1,2]]

arr = set(tuple(i) for i in arr)

if you want to convert it back to list

arr = [list(i) for i in arr]
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