Oct-26-2018, 10:10 PM
I needed code that converted a string into a list of floats, where the string is in the format or '1, 2, .5, 6, 1.23, 10' etc and then the list would be [1, 2, .5, 6, 1.23, 10]
The code I made works but there must be some sort of library that does this, right?
The code I made works but there must be some sort of library that does this, right?
placeholder2='' x_list=[] line=[1, 3, .5, 10, -1.23] for j in line: # line is the string if j!=',': placeholder+=j # placeholder is the same string but with no commas placeholder2=placeholder.split() # placeholder 2 a list of the strings of the numbers I want for i in placeholder2: x_list.append(float(i)) #x_list is the output, the list of integers print(x_list)I needed this code because I had to put a list of integers into a line of a csv file, then take that line out in another program and use each number for a calculation.