I basically have a text file:
-1 2 0 0 0 0 0 2 -1 -1 -2 0 0 -2 2 0 1 0
Who do I want to put on the list of lists so that it looks like this:
[[-1,2,0],[0,0,0],[0,2,-1],[-1,-2,0],[0,-2,2],[0,1,0]]
I have this code so far, but it creates a list of strings in lists.
import os f = open(os.path.expanduser("~/Desktop/example board.txt")) for line in f: for i in line: line = line.strip() line = line.replace(' ',',') line = line.replace(',,',',') print(i) print(line) b.append([line])
This creates [['-1,2,0'],['0,0,0'],['0,2,-1'],['-1,-2,0'],['0,-2,2'],['0,1,0']] This is almost what I want, except for quotation marks.