How do I remove similar tuples in python as in (x,y) and (y,x)
<p>I have a list of tuples [(1,2),(2,1),(4,4)] I want to remove either of these tuples where (a,b) = (b,a). ie.. (1,2) or (2,1)</p>

<p>Assuming the order of the elements in tuple doesn't matter, one way is to do:</p>

<pre><code>In [11]: l = [(1,2), (2,1), (4,4)] 

In [12]: list(set([(x[0], x[1]) if x [0] &lt; x[1] else (x[1], x[0]) for x in l]))
Out[12]: [(1, 2), (4, 4)]
</code></pre>

<p>Edit (A simpler version):</p>

<pre><code>In [15]: list(set(tuple(sorted(x)) for x in l))
Out[15]: [(1, 2), (4, 4)]
</code></pre>

python