Created
July 5, 2024 16:11
-
-
Save 2tony2/8271a994b4c0363435e59a29109f2187 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyIterator: | |
def __init__(self, data): | |
self.data = data | |
self.index = 0 | |
def __iter__(self): | |
return self | |
def __next__(self): | |
if self.index < len(self.data): | |
item = self.data[self.index] | |
self.index += 1 | |
return item | |
else: | |
raise StopIteration | |
my_iter = MyIterator([1, 2, 3]) | |
for item in my_iter: | |
print(item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment