vinay hegde vinay hegde - 4 months ago 6x
Python Question

Removing duplicates(non-exact) tuples from a list in python

Consider a list of tuples:

[(14,1), (10,5), (8,7), (1,14)]

I need to eliminate one of
. So the expected result should be

Note: Order doesn't matter.

I'm aware that
can be used to eliminate exact duplicates. Also combinations would not be of much help too because all of them add up to the same total.


Given the scenario, it would be wise to instead use a set of sets. Sets do not allow duplicates, and order was specified to not matter.

If you have no control of the creation of the data and instead must convert from your current data to this, you can this to convert your current data:

{frozenset(i) for i in dataset}

You have to use frozenset as set is not a hashable type. This is no more restrictive than using a tuple.