how to iterate over several lists?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Jun 5 22:19:20 EDT 2009


On Fri, 05 Jun 2009 11:37:49 -0700, Minesh Patel wrote:

>> def chain(*args):
>>  return (item for seq in args for item in seq)
>>
>> for x in chain(list_a, list_b):
>>    foo(x)
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
> If they are the same length, you can try the zip built-in function.

Which does something *completely different* from what the Original Poster 
was asking for.

Given alist = [1, 2, 3], blist = [4, 5, 6], the OP wants to process:

1, 2, 3, 4, 5, 6

but zip will give:

(1, 3), (2, 5), (3, 6)



-- 
Steven



More information about the Python-list mailing list