indexed() generator
Jonathan Hogg
jonathan at onegoodidea.com
Fri Jan 25 11:07:16 EST 2002
On 25/1/2002 14:29, in article
mailman.1011968940.24241.python-list at python.org, "Michael Chermside"
<mcherm at destiny.com> wrote:
> * So if we make indexed() a standard built-in function, then Python
> users will no longer have to look it up. The only penalty is the
> need to add yet-another-builtin. Admitedly, this is a steep price to
> pay -- but in my own code I find the need for this kind of structure
> (using both a counter AND the items in a loop) to be so common that
> for me it'd be worth it.
>
> So... anyone else agree?
Yes, definitely.
Though perhaps there's room for a new standard module rather than add more
functions to builtins? I'd also want to add other functional-style
definitions like:
def curry( f, *xs ):
return lambda *ys: f( *(xs + ys) )
def rreduce( f, xs, i=None ):
if not xs:
return i
elif len(xs) == 1:
return xs[0]
else:
return f( xs[0], rreduce(f, xs[1:], i) )
[With suitably more robust definitions of course.]
Still, I'd want to move 'map' and 'reduce' into such a module, and I guess
it's too late to reorganise builtins ;-)
If no-one wants more functional definitions, then I'd vote for 'indexed'
being added to builtins. I think the idiom (indexed stepping through a
sequence) is pervasive enough to support it.
So how does one go about "voting" for a PEP, or in particular a particular
option in a PEP?
<http://python.sourceforge.net/peps/pep-0212.html>
I want to vote for 'irange', but called 'indexed' as above - it reads more
naturally for me. I note that the PEP has been under consideration for a
year and a half now.
Jonathan
More information about the Python-list
mailing list