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/2002-July/026500.html below:

[Python-Dev] Single- vs. Multi-pass iterability

[Python-Dev] Single- vs. Multi-pass iterability [Python-Dev] Single- vs. Multi-pass iterabilityDelaney, Timothy tdelaney@avaya.com
Mon, 15 Jul 2002 08:46:01 +1000
> From: David Abrahams [mailto:david.abrahams@rcn.com]
> 
> One other possibility: if x.__iter__() is x, it's a 
> single-pass sequence. I
> realize this involves actually invoking the __iter__ method 
> and conjuring
> up a new iterator, but that's generally a lightweight operation...

Definitely not reliable - it will fail for a file object ... (even with the
changes currently going in).

What would be more reliable (but still not infallible) would be:

if iter(x) == iter(x):
    # this is *definitely* a single-pass iterable

All iterators are by definition single-pass iterables, and with the changes
being made to the file object, the above code would work for all builtin
iterable types as well.

Tim Delaney




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