@anonymous/

SpringgreenOpaqueAssignments

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class ItemCountIterator:
    def __init__(self, iterable):
        self._items = iter(iterable)
        self.count = 0
        self._started = False

    def __iter__(self):
        if self._started:
            raise Exception('Can only start once')
        self._started = True
        for item in self._items:
            self.count += 1
            yield item


items = ItemCountIterator(range(500))
tens = ItemCountIterator(item for item in items if item % 10 == 0)
list(tens)
print(items.count, 'items processed')
print(tens.count, 'tens found')