Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.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.043 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'beginner': 0.05; 'python3': 0.07; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'feeding': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'split': 0.19; 'examples': 0.20; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'dec': 0.30; '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; 'subject:numbers': 0.31; 'linux': 0.33; 'url:python': 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; 'pm,': 0.38; 'sure': 0.39; 'url:mail': 0.40; 'worry': 0.60; 'confirm': 0.64; 'more': 0.64; 'thomas': 0.65; 'side': 0.67; 'e-mail.': 0.70; '2014,': 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; bh=kVM6Kitp4OubsQcUjCkszDFepyRm4aisMOvtJ4T5JDI=; b=urdeC23eIG+6/CrqzlnAHV3oT7Ubh8PhHYj5d9FzdgUrJfYUt3IyxxqbIw0OZGWuYQ ivDYUitP0vJDuAaACgC+Faq12BsF36KpIh5b12A1HJ3eNBE3EWL1Ue5WM7NIyt4MspjT 3Q+7sZBXv9prluolL1/+r8j6aCZdL2O2FAz8KRMogRzVgJD/SUxqSCRhW0BtT7e5Gp9K Y5rpkfukrijblusUpr6VTqVRClaoNDmCODnF3kphrb/Gbeu1nsG8meGRylfWsKn5O3en FuJK9bmR9Kgmz2eRK0yhgoi4usTyPPmxOTnOS0QZpfve7IV66HiYHo7BBNsgckL0cuox DzFQ== MIME-Version: 1.0 X-Received: by 10.224.16.131 with SMTP id o3mr27651918qaa.31.1421016892561; Sun, 11 Jan 2015 14:54:52 -0800 (PST) In-Reply-To: <8077448.xvuXrbCisO@PointedEars.de> References: <7240a574-dfd7-46c3-80eb-0657b41894bb@googlegroups.com> <3bfeea22-cded-4363-92fa-6f1b33ddae16@googlegroups.com> <8077448.xvuXrbCisO@PointedEars.de> Date: Sun, 11 Jan 2015 17:54:52 -0500 Subject: Re: extracting numbers with decimal places from a string From: Joel Goldstick Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421016900 news.xs4all.nl 2890 [2001:888:2000:d::a6]:44181 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83572 On Sun, Jan 11, 2015 at 5:20 PM, 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 > > | $ python > | Python 2.7.9 (default, Dec 11 2014, 08:58:12) > | [GCC 4.9.2] on linux2 > | Type "help", "copyright", "credits" or "license" for more information. > | >>> my_list = "1.23, 2.4, 3.123".split(",") > | >>> my_list > | ['1.23', ' 2.4', ' 3.123'] > | >>> > > | $ python3 > | Python 3.4.2 (default, Dec 27 2014, 13:16:08) > | [GCC 4.9.2] on linux > | Type "help", "copyright", "credits" or "license" for more information. > | >>> 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'] > > This is safer: > > | >>> from re import split > | >>> split(r'\s*,\s*', '1.23, 2.4, 3.123') > | ['1.23', '2.4', '3.123'] > I'm not sure what you are trying to point out as your examples confirm my code. Am I missing something. 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! > -- > 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