Skip to content

Instantly share code, notes, and snippets.

@Philogy
Created August 17, 2023 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Philogy/024c6612260af2b5f88d113df1f9dc9f to your computer and use it in GitHub Desktop.
Save Philogy/024c6612260af2b5f88d113df1f9dc9f to your computer and use it in GitHub Desktop.
Python `range` but with float starts, ends and steps
def frange(start, end=None, step=None):
assert (end is None) <= (step is None)
if end is None:
start, end, step = 0, start, 1
elif step is None:
step = 1
assert step != 0
sign = -1 if step < 0 else 1
v = start
while v * sign < end * sign:
yield v
v += step
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment