list.sort, was Re: [Python-Dev] decorate-sort-undecorate
python at rcn.com
Tue Oct 28 00:11:08 EST 2003
> How about making islice be more lenient about inputs? For example
> x[::-1] should be expressable by islice(x, None, None, -1) when the
> input implements __len__ and __getitem__ -- but it's not. [::-1]
> *does* create a temporary list, because Python doesn't have "views" of
> lists/tuples. islice should also let you go backwards in general,
> islice(x, len(x)-1, None, -2) should work.
Sorry, this idea was examined and rejected long ago. The itertools
principles involved are:
- avoiding calls that cause the whole stream to be realized,
- avoiding situations that require much of the data to be stored in
- an itertool should work well with other tools and handle all kinds of
iterators as inputs.
islice(it, None, None, -1) is a disaster when presented with an infinite
iterator and a near disaster with a long running iterator. Handling
negative steps entails saving data in memory.
The issue of reverse iteration is being dealt with outside the scope of
itertools. See the soon to be revised PEP 322 on reverse iteration. It
will give you the "views" that you seek :-)
More information about the Python-Dev