list of range of floats

S

Steve

I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

TIA
Steve
 
D

Dale Strickland-Clark

Steve said:
I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

TIA
Steve

range only does ints. If you want floats, you'll have to write your own
version.
 
S

Simon Brunning

I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

There would be an *enormous* number of floats between zero and ten. Do
you really want all of them in your list? I hope you have a few
terrabytes of RAM...

Or do you just want the integer values as floats?

fits = list(float(a) for a in range(0, 10))
 
M

Matimus

fits = list(float(a) for a in range(0, 10))

Another way of writing that:

flts = map(float,range(10))
 
L

Larry Bates

Steve said:
I'm trying to create a list range of floats and running into problems.
I've been trying something like:

a = 0.0
b = 10.0

flts = range(a, b)

fltlst.append(flts)

When I run it I get the following DeprecationWarning: integer argument
expected, got float. How can I store a list of floats?

TIA
Steve
What does range of floats mean? How many floats are there
between 0.0 and 10.0? If you want the step to be 1.0
and beginning and ending values will be whole numbers then
this will work:

flts=[float(i) for i in range(1, 11)]

If you want arbitrary starting and ending floats and an
arbitrary step, you will need to write your own function.

-Larry
 
S

Steve

There would be an *enormous* number of floats between zero and ten. Do
you really want all of them in your list? I hope you have a few
terrabytes of RAM...

Or do you just want the integer values as floats?

fits = list(float(a) for a in range(0, 10))

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?

Steve
 
S

Simon Brunning

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.
 
S

Steve

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top