[Python-ideas] __iter__ implies __contains__?

Arnaud Delobelle arnodel at gmail.com
Tue Oct 4 00:02:54 CEST 2011


On 3 October 2011 22:07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Maybe we should be thinking about a "reiterator algebra"
> to sit on top of the iterator algebra.
>
> For example, given two reiterables x and y, zip(x, y)
> would return a reiterable that, when iterated over, would
> extract iterators from x and y and return a corresponding
> iterator.

I'm not sure I understand.  Do you mean something like this snippet
below, but only in the case where the contents of "args" are all
"reiterable"?

>>> class Zip:
...    def __init__(self, *args):
...       self.args = args
...    def __iter__(self):
...       return zip(*self.args)
...
>>> z = Zip('ab', 'cd')
>>> list(z)
[('a', 'c'), ('b', 'd')]
>>> list(z)
[('a', 'c'), ('b', 'd')]

-- 
Arnaud



More information about the Python-ideas mailing list