+ 1

Pgm to sum numbers of string s="1.23,2.4,3.123"in python?

https://code.sololearn.com/W1YpQyq8nfxj/?ref=app

20th Nov 2017, 6:12 PM
Mohit Sharma
2 Answers
+ 8
First: Split the string using "," as a delimiter(will become a list) Second: Parse the elements of the list to float Lastly : Sum the list Here: s = "1.23,2.4,3.123" a_list = s.split(",") a_float_list = map(lamba x: float(x), a_list) sum_of_a_float_list = sum(a_float_list) print(sum_of_a_float_list)
20th Nov 2017, 8:32 PM
David Akhihiero
David Akhihiero - avatar
0
print(sum(list(map(float, s.split(',')))))
20th Nov 2017, 8:32 PM
abolfazl meyarian
abolfazl meyarian - avatar