Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pretty straightforward to accumulate with a <code>defaultdict</code> and then filter:</p> <pre><code>from collections import defaultdict d = defaultdict(list) for tup in list_of_tuples: d[(tup[0],tup[1])].append(tup[2]) d Out[15]: defaultdict(&lt;class 'list'&gt;, {('16', '0000048'): ['PBL'], ('9', '0000022'): ['LRA', 'PBL', 'IBL'], ('12', '0000051'): ['LRA', 'PBL'], ('304', '0000042'): ['PBL'], ('331', '0000040'): ['PBL'], ('41', '0000064'): ['PBL'], ('356', '0000049'): ['PBL'], ('15', '0000015'): ['PBL'], ('8', '0000006'): ['PBL'], ('4', '0000029'): ['LRA'], ('7', '0000014'): ['IBL', 'PBL', 'LRA'], ('32', '0000046'): ['PBL'], ('68', '0000002'): ['PBM'], ('439', '0000005'): ['PBL'], ('10', '0000007'): ['PBM', 'IBL'], ('45', '0000016'): ['PBM']}) </code></pre> <p>And then filter:</p> <pre><code>[(key,val) for key,val in d.items() if len(val) &gt; 1] Out[29]: [(('9', '0000022'), ['LRA', 'PBL', 'IBL']), (('12', '0000051'), ['LRA', 'PBL']), (('7', '0000014'), ['IBL', 'PBL', 'LRA']), (('10', '0000007'), ['PBM', 'IBL'])] </code></pre> <p>And if you really want to get it back into that original format:</p> <pre><code>from itertools import chain [tuple(chain.from_iterable(tup)) for tup in d.items() if len(tup[1]) &gt; 1] Out[27]: [('9', '0000022', 'LRA', 'PBL', 'IBL'), ('12', '0000051', 'LRA', 'PBL'), ('7', '0000014', 'IBL', 'PBL', 'LRA'), ('10', '0000007', 'PBM', 'IBL')] </code></pre> <p>Though I think it most sense to keep it as a <code>dict</code> with (name,id) tuples as the keys, as we generated in the first step.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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