indexed looping, functional replacement?
Alex Martelli
aleax at aleax.it
Sun Nov 10 03:12:12 EST 2002
Bengt Richter wrote:
...
>>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)
Did the OP use str to mean something different than Python's normal builtin
str? If so, then it took a very moderate amount of distraction (which my
cat does freely supply most of the time) to make me believe that str meant
what it most always means -- a constructor for plain strings.
Good occasion then to reiterate the usual advice to people who use the names
of Python's types (or other builtins, I guess, but for some reason it
always seems to be types) for different purposes: don't. By naming your
variables &c with such names as int, float, str, file, list, dict, tuple,
..., you're just causing confusion -- and if you don't fall prey to that
confusion yourselves, you may still trip up others who are trying to help
(or otherwise to read your code).
Alex
More information about the Python-list
mailing list