[Baypiggies] processing multiple lists in step

Brian Harring ferringb at gmail.com
Fri Sep 11 05:16:04 CEST 2009

On Thu, Sep 10, 2009 at 09:19:50AM -0700, Rich Pixley wrote:
> Jeff Enderwick wrote:
> > I like using list-comps in Python. Is there a nice way to process more
> > than one list concurrently in this style? By this, I mean that the 1st
> > iteration would act on L1[0] and L2[0], the 2nd iteration would act on
> > L1[1] and L2[1], and so on. Sorry if the soln is obvious - I am tired
> munge(L1[i], L2[i]) for i in range(len(L1))

Also you can use zip, or itertools.izip...
[munge(x,y) for x,y in zip(l1,l2)]

While you're at it, could just as easily do imap or a generator 
expression ;)

More information about the Baypiggies mailing list