[Pythonmac-SIG] repeat loop question
Chris Barker
cbarker@jps.net
Thu, 07 Dec 2000 10:49:05 -0800
> n = 0
> the_list = ["a", "b", "c"]
>
> for i in the_list:
> print n, i
> n=n+1
>
> ...is there a way of getting the "count" of i without having to hand
> increment n?
Sorry not to put this in my last message, but these are two other
(slightly better) ways of doing it now:
Before 2.0:
for n in range(len(the_list)):
i = sequence[n]
print n, i
After 2.0 (zip is a new function)
for n, i in zip(range(len(the_list)), the_list)
print n, i
-Chris
--
Christopher Barker,
Ph.D.
cbarker@jps.net --- --- ---
http://www.jps.net/cbarker -----@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Water Resources Engineering ------ @ ------ @ ------ @
Coastal and Fluvial Hydrodynamics ------- --------- --------
------------------------------------------------------------------------
------------------------------------------------------------------------