extracting numbers with decimal places from a string

Thomas 'PointedEars' Lahn PointedEars at web.de
Mon Jan 12 01:45:16 CET 2015

Peter Otten wrote:

> Thomas 'PointedEars' Lahn wrote:
>> […]  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...

  print(sum(map(float, s.split(','))))

suffices in this case, of course.

I could have done without the snide remarks.


Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

More information about the Python-list mailing list