Created
January 5, 2012 15:35
-
-
Save shomah4a/1565739 to your computer and use it in GitHub Desktop.
list の 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 ListIter(object): | |
def __init__(self, target): | |
self.target = target | |
self.index = 0 | |
def next(self): | |
if len(self.target) <= self.index: | |
raise StopIteration(); | |
self.index += 1 | |
return self.target[self.index-1] | |
def __iter__(self): | |
return self | |
lst = range(10) | |
for i in ListIter(lst): | |
print i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment