Note that there are some explanatory texts on larger screens.

plurals
  1. POeliminating redundant tuples
    primarykey
    data
    text
    <p>If I have a list of tuples, where each tuple represents variables, <code>a</code>, <code>b</code> and <code>c</code>, how can I eliminate redundant tuples?</p> <p>Redundant tuples are those where <code>a</code> and <code>b</code> are simply interchanged, but <code>c</code> is the same. So for this example:</p> <pre><code>tups = [(30, 40, 50), (40, 30, 50), (20, 48, 52), (48, 20, 52)] </code></pre> <p>my final list should only contain only half of the entries. One possible output:</p> <pre><code>tups = [(30, 40, 50), (20, 48, 52)] </code></pre> <p>another</p> <pre><code>tups = [(40, 30, 50), (20, 48, 52)] </code></pre> <p>etc.</p> <p>Is there an easy Pythonic way to do this? </p> <p>I tried using sets, but <code>(30, 40, 50)</code> is different from <code>(40, 30, 50)</code>, but to me these are redundant and I'd just like to keep one of them (doesn't matter which, but if I could pick I'd prefer the low to high value order). If there was a way to sort the first 2 elements of the tuples, then using the set would work.</p> <p>I am sure I could hack together a working solution (perhaps converting tuples to lists as intermediate step), but I just wanted to see if there's an easy and obvious way to do this that I'm not familiar with.</p> <p>PS: This question partially motivated by <a href="http://projecteuler.net/problem=39" rel="nofollow">PE #39</a>. But even aside from this PE problem, I am now just curious how this could be done easily (or if).</p> <p><strong>Edit</strong>:</p> <p>Just to provide a bit of context for those not familiar with PE #39 - <code>a</code>, <code>b</code>, and <code>c</code> represent sides of a right triangle, so I'm checking if <code>a**2 + b**2 == c**2</code>, clearly the order of <code>a</code> and <code>b</code> don't matter.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload