Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83577
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: extracting numbers with decimal places from a string |
| Date | Mon, 12 Jan 2015 00:46:07 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 28 |
| Message-ID | <1786463.stBbe1naGD@PointedEars.de> (permalink) |
| References | <7240a574-dfd7-46c3-80eb-0657b41894bb@googlegroups.com> <mailman.17591.1421006803.18130.python-list@python.org> <3bfeea22-cded-4363-92fa-6f1b33ddae16@googlegroups.com> <mailman.17595.1421012580.18130.python-list@python.org> <8077448.xvuXrbCisO@PointedEars.de> <mailman.17599.1421016900.18130.python-list@python.org> <2182977.fJl0o3iPdP@PointedEars.de> <mailman.17600.1421019325.18130.python-list@python.org> |
| Reply-To | Thomas 'PointedEars' Lahn <usenet@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1421019988 15608 eJwFwYcBwDAIA7CXwrAJ5zCa/0+oBKNwwgk6Hl6l7naOtgKCr4NorEn2PaVnsECFuR/apf8dRxBp (11 Jan 2015 23:46:28 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Sun, 11 Jan 2015 23:46:28 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNyNEBRDEEBMCWSLCUI9z2X8K7+Ry/oTGw8DCnc2ipt1a5/0HPnuqfJIw+gSc326DRCz3i5xW4om+GldvyAVIeFZQ= |
| Cancel-Lock | sha1:yk0tqC8aMYaCzSI0cLceSwKYFhg= |
| X-NNTP-Posting-Host | eJwNxMEBgDAIA8CVbEkIjiOp7D+C3uMYudJCMsHhuKXzpOdetc8V/wawkRq22GYEXxVV7tAHFnsQgw== |
| Xref | csiph.com comp.lang.python:83577 |
Show key headers only | View raw
Joel Goldstick wrote:
> On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn
> <PointedEars@web.de> 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.
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
extracting numbers with decimal places from a string Store Makhzan <store0a@gmail.com> - 2015-01-11 11:31 -0800
Re: extracting numbers with decimal places from a string Joel Goldstick <joel.goldstick@gmail.com> - 2015-01-11 15:06 -0500
Re: extracting numbers with decimal places from a string Store Makhzan <store0a@gmail.com> - 2015-01-11 12:26 -0800
Re: extracting numbers with decimal places from a string Joel Goldstick <joel.goldstick@gmail.com> - 2015-01-11 16:42 -0500
Re: extracting numbers with decimal places from a string Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-11 23:20 +0100
Re: extracting numbers with decimal places from a string Joel Goldstick <joel.goldstick@gmail.com> - 2015-01-11 17:54 -0500
Re: extracting numbers with decimal places from a string Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 00:12 +0100
Re: extracting numbers with decimal places from a string Joel Goldstick <joel.goldstick@gmail.com> - 2015-01-11 18:35 -0500
Re: extracting numbers with decimal places from a string Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 00:46 +0100
Re: extracting numbers with decimal places from a string Peter Otten <__peter__@web.de> - 2015-01-12 01:09 +0100
Re: extracting numbers with decimal places from a string Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 01:45 +0100
Re: extracting numbers with decimal places from a string Chris Angelico <rosuav@gmail.com> - 2015-01-12 11:17 +1100
Re: extracting numbers with decimal places from a string Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-12 11:45 +1100
Re: extracting numbers with decimal places from a string Grant Edwards <invalid@invalid.invalid> - 2015-01-11 23:06 +0000
Re: extracting numbers with decimal places from a string Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 00:07 +0100
Re: extracting numbers with decimal places from a string Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-12 00:04 +0000
Re: extracting numbers with decimal places from a string Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 02:00 +0100
Re: extracting numbers with decimal places from a string MRAB <python@mrabarnett.plus.com> - 2015-01-12 00:59 +0000
Re: extracting numbers with decimal places from a string Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-12 12:13 +1100
csiph-web