convert element in a list to float
Mark Lawrence
breamoreboy at yahoo.co.uk
Sun Sep 13 16:07:38 EDT 2015
On 13/09/2015 20:55, forums_mp at hotmail.com wrote:
>
> For starters, I googled and saw a plethora of writings on how to convert an entire list from string to float. My interest is on select elements in the list. The output from the print statement: print scenarioList
>
> is as follows
>
> [ '3000000', '"N"', '11400000', '"E"' ]
>
> I need to convert the first and third element to float.
> lat = ( float ) scenarioList [ 0 ]
> lon = ( float ) scenarioList [ 2 ]
>
> fails (invalid syntax). How can I achieve my objective.
>
> Thanks in advance
>
Strong hint, you do not cast the strings to floats, you call the builtin
float() function to do the conversion.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list