Loop over list of pairs
Jp Calderone
exarkun at intarweb.us
Thu Jun 5 16:49:38 EDT 2003
On Thu, Jun 05, 2003 at 04:25:29PM +0200, Thomas G?ttler wrote:
> Hi!
>
> What is the prefered way of loop over
> a list like this?
> mylist=[1, "one", 2, "two", 3, "three"]
From your subject, I'm guessing you want a loop with two variables which
take on the values (1, "one"), then (2, "two"), and finally (3, "three").
If this is the case, this works:
i = iter(mylist)
for (a, b) in zip(i, i):
...
Jp
--
"Minerals are inexhaustible and will never be depleted. A stream of
investment creates additions to proved reserves, a very large in-ground
inventory, constantly renewed as it is extracted... How much was in the
ground at the start and how much will be left at the end are unknown and
irrelevant." -- Morry Adelman, World Renowned Economist
More information about the Python-list
mailing list