If you want to have it even shorter and you are using Python 2.5 or
greater you can also use:
list1 = [float(list_item) for list_item in list1]
Am 25.03.2011 16:27, schrieb Jason Swails:
I'm guessing you have something like
list1=['1.0', '2.3', '4.4', '5.5', ...], right?
You can do this:
for i in range(len(list1)):
list1[i] = float(list1[i])
There's almost certainly a 1-liner you can use, but this should work.
--Jason
On Fri, Mar 25, 2011 at 8:19 AM, joy99 <subhakolkata1...@gmail.com
<mailto:subhakolkata1...@gmail.com>> wrote:
Dear Group,
I got a question which might be possible but I am not getting how to
do it.
If I have a list, named,
list1=[1.0,2.3,4.4,5.5....]
Now each element in the array holds the string property if I want to
convert them to float, how would I do it?
Extracting the values with for and appending to a blank list it would
not solve the problem. If appended to a blank list, it would not
change the property.
If any one of the learned members can kindly suggest any solution?
Thanks in advance.
Best Regards,
Subhabrata.
--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list