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

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

[Python-Dev] Single- vs. Multi-pass iterability [Python-Dev] Single- vs. Multi-pass iterabilityDavid Abrahams David Abrahams" <david.abrahams@rcn.com
Mon, 15 Jul 2002 20:25:38 -0400
From: "Andrew Koenig" <ark@research.att.com>


> Ping> Just fetch the iterator from the container and look for __copy__ on
that.
>
> Yes, that's an alternative.
>
> However the purpose my suggestion of __multiter__ was not to use it to
> test for multiple iteration, but to enable a container to be able to
> yield either a single or a multiple iterator on request.

Why would you want that? Seems like a corner case at best.

> A data structure that supports several different kinds of iteration
> has to provide that support somehow.  What's your suggestion?

class DataStructure(object):
    def __init__(self):
        self._numbers = range(10);
        self._names = [ str(x) for x in range(10) ];

    names = property(lambda self: iter(self._names))
    numbers = property(lambda self: iter(self._numbers))

x = DataStructure();
for y in x.names:
    print repr(y),

print

for y in x.numbers:
    print repr(y),

[Y'know, Python is great. That worked the first time I ran it.]

-Dave








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