Skip to content

Instantly share code, notes, and snippets.

@shomah4a
Created January 5, 2012 15:35
Show Gist options
  • Save shomah4a/1565739 to your computer and use it in GitHub Desktop.
Save shomah4a/1565739 to your computer and use it in GitHub Desktop.
list の iterator ってようはこんなもん?
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