Marcus Goldfish wrote:
I see that an iterator is conceptually distinct from the container
object it iterates over, but I am confused that both the iterator and
container implement __iter__() to support the iterator protocol.
I think this is to simplify the Python runtime. 'for i in c' will work if
Sending to the list, originally this went just to Marcus...
Marcus Goldfish wrote:
I'm trying to understand custom iterators in Python, and created the
following toy class for sequence comparison, which seems to work:
class Foo(object):
"""A toy class to experiment with __eq__ and __iter__"""
> - As Rich pointed out, making Foo into it's own iterator by adding a next()
> method is not a good idea. A simple way to define your own iterator is to
I see that an iterator is conceptually distinct from the container
object it iterates over, but I am confused that both the iterator and
containe
Kent Johnson wrote:
Rich Krauter wrote:
2) Or, if you really want your __eq__ method to use the iterator
returned by __iter__(),
def __eq__(self, other):
for i, j in map(None,self, other):
if i != j:
return False
return True
That's not right either, it will compare Fo
Rich Krauter wrote:
2) Or, if you really want your __eq__ method to use the iterator
returned by __iter__(),
def __eq__(self, other):
for i, j in map(None,self, other):
if i != j:
return False
return True
That's not right either, it will compare Foo([None], []) == Foo(
Marcus Goldfish wrote:
I'm trying to understand custom iterators in Python, and created the
following toy class for sequence comparison, which seems to work:
class Foo(object):
"""A toy class to experiment with __eq__ and __iter__"""
def __init__(self, listA, listB):
self.head, self.tai
I'm trying to understand custom iterators in Python, and created the
following toy class for sequence comparison, which seems to work:
class Foo(object):
"""A toy class to experiment with __eq__ and __iter__"""
def __init__(self, listA, listB):
self.head, self.tail = listA, listB
de