Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

A range function with float increment

Taken from Edvard Majakari's comment in this recipe.

def arange(start, stop=None, step=None):
    if stop is None:
        stop = float(start)
        start = 0.0
    if step is None:
        step = 1.0
    cur = float(start)
    while cur < stop:
        yield cur
        cur += step

For python 2.2 (e.g. pys60) you need to do a "from __future__ import generators" first.
To get the list from the generator, use list(arange(...))
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS