str = [ 3.82133931e-01 4.27354313e-02 1.94678816e-03 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 3.61185198e-06 1.26606241e-01 1.18472360e-01]
The above string has been retrieved from a database text field and I'm trying to convert it back into a list of floats however no matter what I try I can't seem to get rid of the square brackets.
floatList = []for k, v in enumerate(str.split(' ')):if re.search(r'\d', v):item = re.sub(r'\D\S', '', v).rstrip()item = re.sub(r'\[.*?\]/g', '', item)floatList.append(float(item))
I have tried:
item.replace('[', '')
item.replace(']', '')
and with the Ascii codes.
Always the error ValueError: could not convert string to float: '[ 536444501'