Skip to content

Instantly share code, notes, and snippets.

@wrunk
Created October 2, 2012 22:19
Show Gist options
  • Save wrunk/3823685 to your computer and use it in GitHub Desktop.
Save wrunk/3823685 to your computer and use it in GitHub Desktop.
Simple python iterator class
class TestIter(object):
def __init__(self):
self.i = 0
self.l = [1,2,3,4]
def __iter__(self):
return self
def next(self):
if self.i + 1 <= len(self.l):
result = self.l[self.i]
self.i += 1
return result
raise StopIteration
t = TestIter()
for i in t:
print i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment