Skip to content

Instantly share code, notes, and snippets.

@non-static
Created December 1, 2013 08:55
Show Gist options
  • Save non-static/7730150 to your computer and use it in GitHub Desktop.
Save non-static/7730150 to your computer and use it in GitHub Desktop.
class Rev:
def __init__(self, data):
self.data = data
self.index = len(data)
def __iter__(self):
return self
def __next__(self):
if self.index == 0:
raise StopIteration
self.index = self.index -1
return self.data[self.index]
if __name__ == '__main__':
rev = Rev('abcdefg')
for c in rev:
print(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment