how to iterate over several lists?
Ben Finney
ben+python at benfinney.id.au
Fri Jun 5 00:30:05 EDT 2009
Chris Rebert <clp2 at rebertia.com> writes:
> On Thu, Jun 4, 2009 at 9:07 PM, kj<no.email at please.post> wrote:
> >
> >
> > Suppose I have two lists, list_a and list_b, and I want to iterate
> > over both as if they were a single list.
[…]
> Just add the lists together.
>
> for x in list_a + list_b:
> foo(x)
Which, more precisely, creates a *new* list as the concatenation of the
two existing lists.
--
\ “A good politician is quite as unthinkable as an honest |
`\ burglar.” —Henry L. Mencken |
_o__) |
Ben Finney
More information about the Python-list
mailing list