what *is* a class?

Delaney, Timothy tdelaney at avaya.com
Mon Jun 17 20:59:12 EDT 2002


> 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, so that you can write:
> 
>     # iterate over a sorted copy of a list
>     for item in sort(l):
>         ...
> 
> reverse could probabally be made an iterator so that it gets really
> cheap to write:
> 
>     for item in reverse(l):
>         ...
> 
> And i think these functions should work with tuples and strings also.

Personally, I think this is a great idea. But I would exclude extend.

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)
iterable.map(func, iterable, ...)
iterable.filter(func, iterable, ...)
iterable.reduce(func, iterable, ...)
iterable.zip(iterable, ...)
iterable.range([start,] stop[, step])

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

Tim Delaney





More information about the Python-list mailing list