Created
August 17, 2023 09:58
-
-
Save Philogy/024c6612260af2b5f88d113df1f9dc9f to your computer and use it in GitHub Desktop.
Python `range` but with float starts, ends and steps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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