Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96523

Re: convert element in a list to float

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: convert element in a list to float
Date 2015-09-13 21:07 +0100
References <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.495.1442174874.8327.python-list@python.org> (permalink)

Show all headers | View raw


On 13/09/2015 20:55, forums_mp@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

convert element in a list to float forums_mp@hotmail.com - 2015-09-13 12:55 -0700
  Re: convert element in a list to float Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-13 21:07 +0100
  Re: convert element in a list to float Laura Creighton <lac@openend.se> - 2015-09-13 23:02 +0200
    Re: convert element in a list to float Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-13 23:43 +0000
  Re: convert element in a list to float Steven D'Aprano <steve@pearwood.info> - 2015-09-14 11:09 +1000

csiph-web