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/058484.html below:

[Python-Dev] Short-circuiting iterators

[Python-Dev] Short-circuiting iterators [Python-Dev] Short-circuiting iteratorsRaymond Hettinger raymond.hettinger at verizon.net
Wed Dec 7 01:58:10 CET 2005
[Matthew F. Barnes]  Perhaps it would be a useful addition to the
itertools
> module then?
> 
>         itertools.interruptable(iterable)

Any real-world use cases or compelling contrived examples?

ISTM, that the code calling it.stop() would already be in position to
break-out of the iteration directly or set a termination flag.  Instead
of:

    it = itertools.interruptable(iterable):
    for x in it:
        . . .
        if cond(x):
            it.stop()

Why not write:

    for x in iterable:
        . . .
        if cond(x):
            break

If needed, the for-loop can have an else-clause for any processing
needed in the event of interruption.



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