Delete duplicates from a list of pairs with a SameTest

I have a list of pairs, for example like this:

list = {{1, 1.1}, {1.00001, 1.1000001}, {2, 1}} 

I would like to delete a pair which is lies within a certain range of a previous pair (comparing the first element of each pair would be enough). So I would like somehow to implement a SameTest for the first element of each pair.

In my example the first two pairs should be consideres the same and one of them should be deleted. So my wished output would be:

{{1, 1.1}, {2, 1}}

I tried to use Union and DeleteDuplicates with a SameTest, but they only work if I flatten the list, but I would like to keep the structure.

Then I tried

DeleteDuplicatesBy[list, First] 

with works fine (keeps the structure), but it only works if the elements of the list are exactly the same.

I failed to combine a SameTest with DeleteDuplicatesBy.

Is there any neat way to do this?

Edit: note that I have a list of pairs

Replay

There are many ways to accomplish your task. Here is one.

pairs = {{1, 1.1}, {1.00001, 1.1000001}, {2, 1}};
DeleteDuplicates[pairs, Norm[#1 - #2] < .001 &]

{{1, 1.1}, {2, 1}}

Category: list manipulation Time: 2016-07-29 Views: 11

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.109 (s). 12 q(s)