indexed() generator

Michael Hudson mwh at python.net
Fri Jan 25 11:31:36 EST 2002


Jonathan Hogg <jonathan at onegoodidea.com> writes:

> 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.

Guido has consistent rejected such ideas.  I don't know why, but I
think it's a little pointless to try to change his mind.

> 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.]

Ah but this would encourage people to program in a functional style in
Python, which isn't a particularly good idea.  IMO (no H).  Write
loops.

> Still, I'd want to move 'map' and 'reduce' into such a module, and I guess
> it's too late to reorganise builtins ;-)

Yes.

reduce() has to be the most useless builtin around.  I'd remove it, if
it was an option.

> 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.

Hmm, I thought it had been rejected (see above).  I'll prod
python-dev, perhaps.

Cheers,
M.

-- 
    . <- the point                                your article -> .
    |------------------------- a long way ------------------------|
                                        -- Cristophe Rhodes, ucam.chat



More information about the Python-list mailing list