You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
420 B
24 lines
420 B
2 years ago
|
class Iterator:
|
||
|
def __init__(self, origin_list):
|
||
|
self._ref = origin_list
|
||
|
self.n = -1
|
||
|
|
||
|
def __next__(self):
|
||
|
if self.n < len(self._ref) - 1:
|
||
|
self.n += 1
|
||
|
return self._ref[self.n]
|
||
|
raise StopIteration()
|
||
|
|
||
|
|
||
|
class A:
|
||
|
def __init__(self):
|
||
|
self.a = [1, 2, 3, 4]
|
||
|
|
||
|
def __iter__(self):
|
||
|
return Iterator(self.a)
|
||
|
|
||
|
|
||
|
a = A()
|
||
|
for el in a:
|
||
|
print(el)
|