0

I would like to ask how to remove duplicates in this type of list

ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]

i tried set() but still makes an error of: unhashable list

ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]
fpoint=list(set(ppoint))
print (fpoint)

i want to get

[[1,2],[3,4],[5,6],[7,3]

i think set() works only on single value idexes, is there any alternative way for this?

LOURD
  • 1
  • 1
  • 2

2 Answers2

4

You can do like this,

In [9]: list(set(map(tuple,ppoint)))
Out[9]: [(1, 2), (5, 6), (3, 4), (7, 3)]
Rahul K P
  • 15,740
  • 4
  • 35
  • 52
0

You could just use an if statement? But if you take a look at the collections module, I'm sure ther would be an easier solution.

An if statement could look like:

for coords in ppoint:
    if coords not in fpoint:
        newlist.append(coords)
Adam
  • 709
  • 4
  • 16