Is there a better algorithm?

mr mario.ruggier at gmail.com
Fri Jan 2 16:38:15 EST 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
    try:
        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