Message296646
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. |
|
Date |
User |
Action |
Args |
2017-06-22 17:19:12 | hiba | set | recipients:
+ hiba, docs@python |
2017-06-22 17:19:12 | hiba | set | messageid: <1498151952.1.0.340362281065.issue30738@psf.upfronthosting.co.za> |
2017-06-22 17:19:12 | hiba | link | issue30738 messages |
2017-06-22 17:19:11 | hiba | create | |
|