Created on 2017-06-22 17:19 by hiba, last changed 2017-06-22 17:31 by eryksun. This issue is now closed.
Messages (2) | |||
---|---|---|---|
msg296646 - (view) | Author: Hiba (hiba) | Date: 2017-06-22 17:19 | |
class Reverse: """Iterator for looping over a sequence backwards.""" def __init__(self, data): self.data = data self.index = len(data) def __iter__(self): return self def next(self): if self.index == 0: raise StopIteration self.index = self.index - 1 return self.data[self.index] ********************************************* The next() method in the above code snippet(from 9.9 Iterators section in Tutorial is not correctly overridden. It's missing the underscores. |
|||
msg296647 - (view) | Author: Eryk Sun (eryksun) * ![]() |
Date: 2017-06-22 17:31 | |
Did you try the example in Python 2? Did you click on the "next" link in the preceding paragraph? Please read the following: https://docs.python.org/2/library/stdtypes.html#iterator.next iterator.next() Return the next item from the container.... In Python 3, this method was renamed `__next__`. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2017-06-22 17:31:46 | eryksun | set | status: open -> closed nosy: + eryksun messages: + msg296647 resolution: not a bug stage: resolved |
2017-06-22 17:19:12 | hiba | create |