Skip to content

Instantly share code, notes, and snippets.

@tclh123
Created November 22, 2012 15:50
Show Gist options
  • Save tclh123/4131814 to your computer and use it in GitHub Desktop.
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
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