Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created May 8, 2012 03:29
Show Gist options
  • Save j2labs/2632324 to your computer and use it in GitHub Desktop.
Save j2labs/2632324 to your computer and use it in GitHub Desktop.
what xrange might look like
class xrange(object):
def __init__(self, x):
self.offset = 0
self.x = x
def __len__(self):
return self.x
def __iter__(self):
return self
def next(self):
if self.offset == self.x:
raise StopIteration
retval = self.offset
self.offset += 1
return retval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment