views:

60

answers:

2

For example, if I have

a=[['a','b','c'],[1,2,3],['d','e','f'],[4,5,6]]

How can I get each element of a to be an argument of say, zip without having to type

zip(a[0],a[1],a[2],a[3])?

+11  A: 

Using sequence unpacking (thanks to delnan for the name):

zip(*a)
Joe D
Exactly. Btw, this is called sequence unpacking.
delnan
Nice, thanks Joe D.
JonC
Dammit, only 1 vote away from a badge... ;-)
Joe D
@Joe: One vote away from *two* badges. Enjoy. :)
Roger Pate
A: 

Chain()?

http://docs.python.org/library/itertools.html#itertools.chain

nm, read it wrong. That won't work.

Matt_JD
Nope. That will create an iterator over what is essentially all the inner lists added together.OP is trying to iterate in parallel rather than sequence.
recursive
Yeah realised straight after posting it :(
Matt_JD