Converting an iterator to a list using the list constructor: : Iterator « Class « Python Tutorial
- Python Tutorial
- Class
- Iterator
class TestIterator:
value = 0
def next(self):
self.value += 1
if self.value > 10: raise StopIteration
return self.value
def __iter__(self):
return self
ti = TestIterator()
list(ti)
11.22.Iterator |
| 11.22.1. | The Iterator Protocol |
| 11.22.2. | Converting an iterator to a list using the list constructor: |