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


Groups > comp.lang.python > #96528

Re: convert element in a list to float

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 <lac@openend.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'float': 0.05; 'cc:addr :python-list': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'advance': 0.10; 'output': 0.13; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'googled': 0.16; 'help?': 0.16; 'message-id:@fido.openend.se': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'string': 0.17; 'element': 0.18; 'laura': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; 'sep': 0.22; 'select': 0.23; 'elements': 0.23; 'subject:list': 0.26; '-0700,': 0.29; 'follows': 0.29; 'received:se': 0.29; 'cc:no real name:2**1': 0.29; 'convert': 0.29; 'print': 0.30; 'skip:[ 10': 0.31; 'third': 0.33; 'list': 0.34; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'list.': 0.37; 'does': 0.39; 'entire': 0.61; 'header:Message-Id:1': 0.61; 'interest': 0.64; 'saw': 0.77; 'header:In-reply-to:1': 0.84; 'starters,': 0.84; 'email addr:hotmail.com': 0.89; 'to:addr:hotmail.com': 0.98
To forums_mp@hotmail.com
cc python-list@python.org, lac@openend.se
From Laura Creighton <lac@openend.se>
Subject Re: convert element in a list to float
In-reply-to <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com>
References <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com>
Comments In-reply-to forums_mp@hotmail.com message dated "Sun, 13 Sep 2015 12:55:13 -0700."
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-ID <3623.1442178175.1@fido>
Content-Transfer-Encoding quoted-printable
Date Sun, 13 Sep 2015 23:02:55 +0200
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [82.96.5.2]); Sun, 13 Sep 2015 23:03:00 +0200 (CEST)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.500.1442178190.8327.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442178190 news.xs4all.nl 23804 [2001:888:2000:d::a6]:55768
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96528

Show key headers only | View raw


In a message of Sun, 13 Sep 2015 12:55:13 -0700, forums_mp@hotmail.com writes:
>
>
>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

Does this help?

>>> l = [ '3000000', '"N"', '11400000', '"E"' ]
>>> [float(l[0]), l[1], float(l[2]), l[3]]
[3000000.0, '"N"', 11400000.0, '"E"']

Laura

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