+ 1
Pgm to sum numbers of string s="1.23,2.4,3.123"in python?
2 Réponses
+ 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)
0
print(sum(list(map(float, s.split(',')))))