extracting numbers with decimal places from a string

Thomas 'PointedEars' Lahn PointedEars at web.de
Mon Jan 12 00:12:28 CET 2015


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.

> 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.



More information about the Python-list mailing list