Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'element': 0.07; 'float': 0.07; 'string': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; 'trailing': 0.09; 'jan': 0.12; 'comma': 0.16; 'confuse': 0.16; 'lambda': 0.16; 'optional': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'unnecessary.': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'first.': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'performing': 0.26; 'header:X -Complaints-To:1': 0.27; 'character': 0.29; "skip:' 10": 0.31; '>>>>': 0.31; 'quotes': 0.31; 'subject:numbers': 0.31; 'supposed': 0.32; 'guess': 0.33; 'subject:from': 0.34; 'subject:with': 0.35; 'computing': 0.35; 'but': 0.35; 'list': 0.37; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'space': 0.40; 'sum': 0.64; 'thomas': 0.65; '2015': 0.84; 'joel': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: extracting numbers with decimal places from a string Date: Mon, 12 Jan 2015 01:09:21 +0100 Organization: None References: <7240a574-dfd7-46c3-80eb-0657b41894bb@googlegroups.com> <3bfeea22-cded-4363-92fa-6f1b33ddae16@googlegroups.com> <8077448.xvuXrbCisO@PointedEars.de> <2182977.fJl0o3iPdP@PointedEars.de> <1786463.stBbe1naGD@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p57bdb9c4.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421021375 news.xs4all.nl 2832 [2001:888:2000:d::a6]:40100 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83580 Thomas 'PointedEars' Lahn wrote: > Joel Goldstick wrote: > >> On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn >> wrote: >>> Joel Goldstick wrote: >>>> Am I missing something. >>> ^ >>> […] >>> You are missing a leading space character because in the string the >>> comma was followed by one. >> >> I see that now. Performing float on each element of the list will >> take care of that, or I guess .strip() on each first. > > As I showed, .strip() is unnecessary. But float() is always necessary for > computing the sum and suffices indeed together with s.split() if s is just > a comma-separated list of numeric strings with optional whitespace leading > and trailing the comma: > > print(sum(map(lambda x: float(x), s.split(','))) > > Please trim your quotes to the relevant minimum. Hm, can you explain what this lambda x: float(x) is supposed to achieve? I mean other than to confuse a newbie...