something for itertools

Daniel Nogradi nogradi at gmail.com
Fri Sep 15 17:40:24 EDT 2006


In a recent thread,
http://mail.python.org/pipermail/python-list/2006-September/361512.html,
a couple of very useful and enlightening itertools examples were given
and was wondering if my problem also can be solved in an elegant way
by itertools.

I have a bunch of tuples with varying lengths and would like to have
all of them the length of the maximal and pad with None's. So
something like

a = ( 1, 2, 3 )
b = ( 10, 20 )
c = ( 'x', 'y', 'z', 'e', 'f' )

should turn into

a = ( 1, 2, 3, None, None )
b = ( 10, 20, None, None, None )
c = ( 'x', 'y', 'z', 'e', 'f' )

Of course with some len( ) calls and loops this can be solved but
something tells me there is a simple itertools-like solution.

Any ideas?



More information about the Python-list mailing list