indexed looping, functional replacement?

Bengt Richter bokr at oz.net
Sun Nov 10 02:17:54 EST 2002


On Sat, 09 Nov 2002 19:00:21 GMT, Alex Martelli <aleax at aleax.it> wrote:
[...]
>In Python 2.3, the enumerate built-in will do just that:
>
>[alex at lancelot alf]$ python2.3
>Python 2.3a0 (#4, Nov  6 2002, 09:18:17)
>[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
>>>> for x in enumerate('ciao'): print x
>...
>(0, 'c')
>(1, 'i')
>(2, 'a')
>(3, 'o')
>>>>
>
>In Python 2.2, you can try various inferior alternatives, e.g.:
>
>for f, i in zip(fn, range(len(fn))):
>    f(str(i))
>

Is there something I'm missing, or did the cat distract you ;-)

 >>> for f, s in zip(fl, sl):
 ...     f(s)
 ...
 f1: bbb
 f2: sdf
 f3: sdw

(fl and sl being alternate names for fn and str as used)

Regards,
Bengt Richter



More information about the Python-list mailing list