-2

I have a 2D point list like:

points_list = [[2,1],[3,1],[2,1],[2,2],[2,1],[2,2]]

I want to find the duplicated 2D points, and only leave one copy of each duplicated point in the list. Such that to get a result like:

result_list = [[2,1],[3,1],[2,2]]

I know a stupid method to solve the problem, but cannot find a elegant way. Hoping someone could provide some easy ways. Thanks!

1 Answers1

-1

Here's a webpage that enumerates many possible ways of doing it (I'd go for the 4th one) :

https://www.peterbe.com/plog/uniqifiers-benchmark

Therefore, quoted from the link above :

def noDuplicates(seq):
    # order preserving 
    noDupes = [] 
    [noDupes.append(i) for i in seq if not noDupes.count(i)]
    return noDupes
Vivick
  • 3,434
  • 2
  • 12
  • 25
  • Not a "link-only answer" anymore – Vivick May 29 '17 at 22:57
  • Yes, but it uses a list comprehension with a side effect (very bad form), and uses `.count`. this is a very inefficient approach since `.count` iterates the whole list making the overall solution quadratic time. – juanpa.arrivillaga May 29 '17 at 23:29