I am reading a line from the text file: The text file looks like this:
2 [209:0.3720511,256:0.3525813,300:0.3466443,148:0.3456179,246:0.3443979,267:0.3425797,126:0.3397026,10:0.3379505,266:0.3357508,301:0.334953]
I am trying to convert [209:0.3720511,256:0.3525813,300:0.3466443,148:0.3456179,246:0.3443979,267:0.3425797,126:0.3397026,10:0.3379505,266:0.3357508,301:0.334953]
in list containing values [209,256,300,148,246,267...]
I followed this link : Convert string representation of list to list
Here is my code but it's not working:
with open("file.txt", "r") as text_file:
for line in itertools.islice(text_file, 19, 20): # only one line
print(ast.literal_eval(line.split(" ")[1]))
giving error.
Please help.