Input list

res = ['1.000000e+000', '2.000000e+000', '1.000000e+000', '2.000000e+000']

output list should be like this

res = [1.000000e+000, 2.000000e+000, 1.000000e+000, 2.000000e+000]

Can you please suggest me how to produce this desired output using python

2

There are 2 best solutions below

3
Tim Roberts On

Those are not "float values with single quotes". Those are strings. You can do

res = list(map(float,res))

or a full comprehension

res = [float(i) for i in res]
0
St_Ecke On

just iterate over the elements in the list and cast the strings as floats. In this case I used a list comprehension (basically a loop):

res = [float(i) for i in res]