list of range of floats
Steve
samckain at southslope.net
Wed Feb 14 22:00:00 EST 2007
On Wed, 14 Feb 2007 18:46:34 +0000, Simon Brunning wrote:
> 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.
You hit it on the head Simon. Thanks for strightening out my thinking.
Steve
More information about the Python-list
mailing list