Skip to content

Instantly share code, notes, and snippets.

@tclh123
Created November 22, 2012 15:50
Show Gist options
  • Select an option

  • Save tclh123/4131814 to your computer and use it in GitHub Desktop.

Select an option

Save tclh123/4131814 to your computer and use it in GitHub Desktop.

Revisions

  1. tclh123 created this gist Nov 22, 2012.
    17 changes: 17 additions & 0 deletions frange2
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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