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/2005-December/058507.html below:

[Python-Dev] Short-circuiting iterators

[Python-Dev] Short-circuiting iterators [Python-Dev] Short-circuiting iteratorsRaymond Hettinger raymond.hettinger at verizon.net
Thu Dec 8 05:15:55 CET 2005
[Matthew F. Barnes]
> The ability to remotely terminate a for-loop also struck me as
somewhat
> interesting:
> 
>     def estimate(item, iterable):
>         . . .
>         if good_enough:
>             iterable.stop()
>             return result
> 
>     for x in iterable:
>         . . .
>         approx *= estimate(x, iterable)

Good inspiration; wrong technique.  For the RightWay(tm), try a
functional approach composing a target calculation with a function
generating successively more accurate approximations and a consumer
function that stops when the desired accuracy is achieved.  The idea is
to decouple the steps into side-effect-free, reusable components.  For a
worked-out, comprehensive example, see
http://www.md.chalmers.se/~rjmh/Papers/whyfp.pdf .


> But these are highly contrived and hardly compelling.

That suggests an answer to your earlier question as to whether
itertools.interruptable(iterable) would be a useful addition ;-)



Raymond

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