After parsing a file, I obtain a list of strings containing numerical values, let's say:
my_list = ['1', '-2.356', '00.57', '0', '-1', '02678', '0.005367', '0', '1']
In order to obtain these numerical values, I do the following:
new_list = [float(i) for i in my_list] .
The problem is that the integer values - which are a majority in the file I am handling, are also converted to float and thus occupy more memory - let alone other issues (I have to use some of them as indexes - thus they need to be converted to int at some point..)
Is there an efficient way to convert from string to float only those needed (I must not lose any precision) and to integer all the other ones?