looping through a list of lists.

Peter Otten __peter__ at web.de
Wed Oct 8 13:15:44 EDT 2003


Rob Hunter wrote:

> The responder to this post has a cool way of doing it, but it won't
> work (I believe) if you have an arbitrary number of sublists.  Can you
> clarify the problem?  Do you have an arbitrary number of sublists?  Or
> is it always 3?

I you are referring to the zip trick posted by SBrunning at trisystems.co.uk,
it *does work for an arbitrary number of sublists, but not for
arbitrary-length sublists:

>>> for loc in zip(*"alpha beta gamma delta".split()):
...     print loc
...
('a', 'b', 'g', 'd')
('l', 'e', 'a', 'e')
('p', 't', 'm', 'l')
('h', 'a', 'm', 't')
>>>

Peter




More information about the Python-list mailing list