grid = [ ['x'] * w ] * h
grid[0[2]] = 'a'
This was a test to make a grid-like structure. The thing is, I can't access a nested list because integers can't be subscripted. I've seen problems like this but they aren't a recalling problem. Any suggestions?
[...]*nfor mutable objects if you plan to modify the string, or else every other instance of that string in your grid will automatically change from under you. To elaborate, strings are effectively immutable in python, so it's not['x']*wthat's the problem, but ifrows = [['a','b','c']]*3, and you modify a row, all the other rows will change. Use[['x' for c in range(numCols)] for r in range(numRows)].[['x']*3 for c in range(numCols)]also works since the inner list is recreated each time.