A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-October/039679.html below:

list.sort, was Re: [Python-Dev] decorate-sort-undecorate

list.sort, was Re: [Python-Dev] decorate-sort-undecorateRaymond Hettinger python at rcn.com
Tue Oct 28 00:11:08 EST 2003
[Bob Ippolito]
> 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
memory,
 - 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 :-)


Raymond Hettinger


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4