what *is* a class?

holger krekel pyth at devel.trillke.net
Tue Jun 18 07:11:04 EDT 2002

Delaney, Timothy wrote:
> > From: holger krekel [mailto:pyth at devel.trillke.net]
> > 
> > I agree that this is a good thing. But it wouldn't hurt to have
> > 
> >     reverse, sort, extend
> > 
> > as standalone functions somewhere in the stdlib.  They would return
> > a copy...
> Personally, I think this is a great idea. But I would exclude extend.

I'd even like to have something like extend (see below) ...

> I think there should be a library of "iterable" functions (perhaps in
> builtins ;) which return an iterator, and accept any iterable (where
> appropriate). Let's call it builtin module iterable (or maybe iterator ...).
> Functions defined in this module would be specified to not modify the
> original iterable (indeed, should all call iter(iterable) before doing
> anything). Of course, whee appropriate a function passed in could modify the
> original.
> Examples of such functions would be:
> iterable.sort(iterable [, func])
> iterable.reverse(iterable)

that would be quite expensive for common cases (like lists).  reverse and 
sort should also allow to operate on complete sequence types. 
iterable.reverse could be cheap again then and iterable.sort would be
as expensive as it is now (but not requiring any inplace-steps).

> iterable.map(func, iterable, ...)
> iterable.filter(func, iterable, ...)
> iterable.reduce(func, iterable, ...)
> iterable.zip(iterable, ...)
> iterable.range([start,] stop[, step])

yes, indeed! i'd probably do 'from iterable import *' :-)

seriously, i'd include something like concat as an iterable, too: 

    for item in iterable.concat(iter1,iter2):
        # items iterates with iter1, then iter2 

All the the iterable functions should accept sequence and 
possibly mapping types (same semantics as for 'for'-loops now).

> There have been suggestions like this before, but I don't recall one for
> sort() and reverse(), and these two have fired me :)

I think an iterable module should be done. Although there would 
inevitably be overlapping functionality with the current builtins.

Maybe something for the train ride to EuroPython :-)

> Tim Delaney

    holger krekel

More information about the Python-list mailing list