A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2010-October/104629.html below:

[Python-Dev] [Python-ideas] minmax() function returning (minimum, maximum) tuple of a sequence

[Python-Dev] [Python-ideas] minmax() function returning (minimum, maximum) tuple of a sequenceCarl M. Johnson cmjohnson.mailinglist at gmail.com
Mon Oct 11 07:56:47 CEST 2010
On Sun, Oct 10, 2010 at 2:55 PM, Zac Burns <zac256 at gmail.com> wrote:

> This could be generalized and placed into itertools if we create a function
> (say, apply for lack of a better name at the moment) that takes in an
> iterable and creates new iterables that yield each from the original
> (avoiding the need for a list) holding only one in memory. Then you could
> pass the whatever function you wanted to run the iterables over an get the
> result back in a tuple.

Time machine partially beat you to this one. Look at the docs on itertools.tee

    tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n

Can be used like so:

>>> it = iter(range(100))
>>> it1, it2 = itertools.tee(it)
>>> max(it1)
99
>>> min(it2)
0

This doesn't quite have the memory characteristics you describe, but
it's about as good as you can expect in a single threaded environment.
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