Is there a better algorithm?
Markus Brueckner
news at slash-me.net
Fri Jan 2 13:55:43 EST 2009
Hi,
Fuzzyman wrote:
> I'm sure there is a clever one liner using the Python 2.5 ternary
> expression syntax. On the other hand I'm not sure it would be very
> readable, so a straightforward (if less clever) solution is probably
> better.
that would be something like this (using a generator)
L = [(1, 2), (3, 4, 5), (6, 7)]
g = ( ((e[0],None,e[1]) if len(e)==2 else (e[0],e[1],e[2])) for e in L)
for elem in g:
print elem
So long,
Markus
P.S: No, I don't consider that more readable than your example ;-)
--
"Hacking is like having sex: you get in, you get out and you hope that you
did not leave anything which can be traced back to you" - Unbekannt
More information about the Python-list
mailing list