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

A range function with float increment (See related posts)

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(...))

You need to create an account or log in to post comments to this site.


Click here to browse all 4860 code snippets

Related Posts