I have a list of x,y coordinates and I want to sort them based on the x coordinate, then y coordinate when x is the same and eliminate duplicates of the same coordinates. For example, if the list is:

[[450.0, 486.6], [500.0, 400.0], [450.0, 313.3], [350.0, 313.3], [300.0, 400.0],
[349.9, 486.6], [450.0, 313.3]]

I want to rearrange it to:

[[300.0, 400.0], [349.9, 486.6], [350.0, 313.3], [450.0, 313.3], [450.0, 486.6],
[500.0, 400.0]]

Can anyone tell me the solution?
May 20, 2019 in Python 2,046 views

## 1 answer to this question.

You can try and De-dupe it with a dict.

>>> L = [[450.0, 486.6], [500.0, 400.0], [450.0, 313.3], [350.0, 313.3], [300.0, 400.0], [349.9, 486.6], [450.0, 313.3]]
>>> sorted({tuple(x): x for x in L}.values())
[[300.0, 400.0],
[349.9, 486.6],
[350.0, 313.3],
[450.0, 313.3],
[450.0, 486.6],
[500.0, 400.0]]
• 13,300 points

## Python: list of lists

Lists are a mutable type - in ...READ MORE

+1 vote

## Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

## How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

## Where can I get the list of Python keywords?

Just import a module “keyword”. Here you ...READ MORE

## How to return dictionary keys as a list in Python?

Now, in Python >= 3.3, I get something ...READ MORE

## Double the value of array on a match - Python

I want to iterate through the elements ...READ MORE

## Why do I get "List index out of range" when trying to add consecutive numbers in a list using "for i in list"?

Given the following list a = [0, 1, ...READ MORE