Created
November 22, 2012 15:50
-
-
Save tclh123/4131814 to your computer and use it in GitHub Desktop.
"A faster range-like function that does accept float increments" from http://wiki.woodpecker.org.cn/moin/PyCkBk-1-16
This file contains 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 frange2(start, end=None, inc=1.0): | |
"A faster range-like function that does accept float increments..." | |
if end == None: | |
end = start + 0.0 | |
start = 0.0 | |
else: start += 0.0 # force it to be a float | |
count = int((end - start) / inc) | |
if start + count * inc != end: | |
# Need to adjust the count. AFAICT, it always comes up one short. | |
count += 1 | |
L = [start] * count | |
for i in xrange(1, count): | |
L[i] = start + i * inc | |
return L |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment