Is there a better algorithm?

mr mario.ruggier at
Fri Jan 2 22:38:15 CET 2009

As has been noted, the best is to fix the input to be regular-3-
tuples. For the fun of it, here's another variation of a solution:

tuples = [(1, 2), (3, 4, 5), (6, 7)]

def triple_or_pair(seq):
    u = None
        k, u, v = seq
    except ValueError:
        k, v = seq
    return k, u, v

for k, u, v in [ triple_or_pair(seq) for seq in tuples ]:
    print k, u, v

More information about the Python-list mailing list