[Python-ideas] An ABC representing "Iterable, Sized, Container"
mertz at gnosis.cx
Fri Jul 22 13:58:36 EDT 2016
On Fri, Jul 22, 2016 at 8:48 AM, Chris Angelico <rosuav at gmail.com> wrote:
> IMO, no. Some iterators can be restarted by going back to the original
> iterable and requesting another iterator, but with no guarantee that
> it will result in the exact same sequence (eg dict/set iterators).
Sequences don't give you this *guarantee* either. A trivial example:
def __getitem__(self, ndx):
# In "real world" this might be meaningful condition and update
if random() < .333:
if isinstance(ndx, slice):
for n in range(ndx.start, ndx.stop, ndx.step or 1):
self[n] += 1
self[ndx] += 1
> What you might be looking at is a protocol for "bookmarking" or
> "forking" an iterator. That might be more useful. For example:
How is this different from itertools.tee()?
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas