Path: csiph.com!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'float': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'builtin': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'advance': 0.10; 'output': 0.13; 'googled': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.16; 'string': 0.17; 'element': 0.18; 'language': 0.19; 'lawrence': 0.22; 'select': 0.23; 'elements': 0.23; 'header :In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X-Complaints-To:1': 0.26; 'function': 0.28; 'follows': 0.29; 'convert': 0.29; 'print': 0.30; 'language.': 0.32; 'third': 0.33; 'list': 0.34; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'list.': 0.37; 'to:addr:python.org': 0.40; 'mark': 0.40; 'entire': 0.61; 'charset:windows-1252': 0.62; 'interest': 0.64; 'our': 0.64; 'cast': 0.66; 'saw': 0.77; 'pythonistas,': 0.84; 'starters,': 0.84; 'email addr:hotmail.com': 0.89 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: convert element in a list to float Date: Sun, 13 Sep 2015 21:07:38 +0100 References: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 195.147.66.69 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 In-Reply-To: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442174874 news.xs4all.nl 23815 [2001:888:2000:d::a6]:37139 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96523 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