list of range of floats

Simon Brunning simon at brunningonline.net
Wed Feb 14 13:46:34 EST 2007


On 2/14/07, Steve <samckain at southslope.net> wrote:
> After re-reading my original post I was pretty vague. I'm trying to creat
> a list of ranges of floats, 0.0 10.0, 11 20, etc then checking to see if
> an float, example 12.5 falls in the list and if so get the list index of
> where it is in the index. Does this make sense?

Ah, you want to know if a certain number is between to other numbers.
That's not what range() is for - range() is for generating lists of
integers. You can use it to do a between test for integers, I suppose,
but even for integers it's a pretty poor way of going about it -
you'll be creating a potentially large lists of integers, only to
throw it away again.

Consider something like:

def between(lower, upper, target):
    return lower < target < upper

Works for integers and floats interchangably. Or better still, do the
lower < target < upper thing inline.

-- 
Cheers,
Simon B
simon at brunningonline.net
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list