Created
March 2, 2018 21:30
-
-
Save brentshermana/16fff59d666250e0222a37efb9df0622 to your computer and use it in GitHub Desktop.
Python generator based iterator
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 X: | |
def __init__(self, l): | |
self.l = l | |
def __iter__(self): | |
for x in self.l: | |
yield x | |
x = X([1,2,3]) | |
for i in x: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment