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


Groups > comp.lang.python > #83576

Re: extracting numbers with decimal places from a string

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'beginner': 0.05; 'element': 0.07; 'float': 0.07; 'string': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'comma': 0.16; 'feeding': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'first.': 0.19; 'examples': 0.20; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'performing': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'character': 0.29; 'skip:@ 10': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'gives': 0.31; "skip:' 10": 0.31; 'twitter:': 0.31; '>>>>': 0.31; 'subject:numbers': 0.31; 'url:python': 0.33; 'guess': 0.33; 'subject:from': 0.34; 'subject:with': 0.35; 'something': 0.35; 'no,': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'list': 0.37; 'pm,': 0.38; 'that,': 0.38; 'sure': 0.39; 'space': 0.40; 'url:mail': 0.40; 'worry': 0.60; 'confirm': 0.64; 'thomas': 0.65; 'side': 0.67; 'e-mail.': 0.70; '(is': 0.84; '2015': 0.84; 'terrible': 0.84; 'joel': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=2mP4Pon+T50R2VKsUu+HJjoZgV8FDUiNkN7LuVi/Fzk=; b=kzVoQHFfQ7CHUYHemoULhzdOkCbDi4Q8IsgSMcm2BY1QnSvgsja4X92zzYNz1TbDRA G+ojS/PSM+Qdo8Zdv/qUTI5EtavckJXZeHU3M/hIbjOBCSjY2TBpWWu/eW9NBKLxpOqp CFyvHDwqJMTCQnjd40/19P+blSB0EwNJ9RWDkhdOgxuApZ157Q5L066CkPw9wrNToHLD IqQ0PspMJfrp8h7DSKgV9fK8gk3pFGjrY2hbdiCV2uK0CCdZvIANUsHlZdmYe2hpZvDR 2c7UVQcyiZkd7n+eled/itpOJD5zyWa+XwOTfdikPqqfIcLim94+SNPC0BiZmr1rDOio +HEw==
MIME-Version 1.0
X-Received by 10.140.41.113 with SMTP id y104mr41987192qgy.51.1421019322347; Sun, 11 Jan 2015 15:35:22 -0800 (PST)
In-Reply-To <2182977.fJl0o3iPdP@PointedEars.de>
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>
Date Sun, 11 Jan 2015 18:35:22 -0500
Subject Re: extracting numbers with decimal places from a string
From Joel Goldstick <joel.goldstick@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.17600.1421019325.18130.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421019325 news.xs4all.nl 2944 [2001:888:2000:d::a6]:57022
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83576

Show key headers only | View raw


On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn
<PointedEars@web.de> wrote:
> Joel Goldstick wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> Joel Goldstick wrote:
>>>> my_list = "1.23, 2.4, 3.123".split(",")
>>>>
>>>> that will give you ['1.23', '2.4', '3.123']
>>>
>>> No, it gives
>>>
>>> […]
>>> | >>> my_list = "1.23, 2.4, 3.123".split(",")
>>> | >>> my_list
>>> | ['1.23', ' 2.4', ' 3.123']
>                ^       ^
>>> | >>>
>>>
>>> In order to get the result you described, one needs at least
>>>
>>> | >>> '1.23, 2.4, 3.123'.split(', ')
>>> | ['1.23', '2.4', '3.123']
>>>
>>> […]
>>
>> I'm not sure what you are trying to point out as your examples confirm
>> my code.
>
> No, they don't.
>
>> Am I missing something.
>                         ^
> (Is that a question.)
>
> 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 for feeding a beginner regex solutions, I'm on the side that this
>> is a terrible idea.  Regex is not something a beginner should worry
>> about!
>
> NAK.
>
> --
> PointedEars
>
> Twitter: @PointedEars2
> Please do not cc me. / Bitte keine Kopien per E-Mail.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com

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


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