Skip to content

Instantly share code, notes, and snippets.

@theelous3
Created April 2, 2018 21:51
Show Gist options
  • Save theelous3/0a62f6d36478384f7ea638ede2ba0bb6 to your computer and use it in GitHub Desktop.
Save theelous3/0a62f6d36478384f7ea638ede2ba0bb6 to your computer and use it in GitHub Desktop.
def range(*args):
def inner(start=0, stop=..., step=1):
if stop is ...:
stop = float('inf')
while start < stop:
yield start
start += step
if len(args) == 1:
return inner(stop=args[0])
else:
return inner(*args)
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(10, 20))
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> list(range(10, 20, 4))
[10, 14, 18]
>>> list(zip(range(20), range(1, ..., 2)))
[(0, 1), (1, 3), (2, 5), (3, 7), (4, 9), (5, 11), (6, 13), (7, 15), (8, 17), (9,
19), (10, 21), (11, 23), (12, 25), (13, 27), (14, 29), (15, 31), (16, 33), (17,
35), (18, 37), (19, 39)]
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment