-1

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

sand
  • 35
  • 6

2 Answers2

3

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]
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
1

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]
St_Ecke
  • 161
  • 1
  • 9