I wanted to try to make a simple game to play in my terminal and I am stuck on this problem.
I have tried
l[y][x] = l[y][x].replace(' ','2')
And
l[y][x] = '2'
And all of these returns a type error
'str' object does not support item assignment
.
how do I solve the problem above?
Edit:
l
contains
['111111111',
'120000001',
'100000001',
'100000001',
'111111111'
]
CodePudding user response:
You need to convert your list l into characters - what you have is a list of string elements.
#convert elements into characters
m = [list(x) for x in l]
print(m)
print(m[1][2])
m[1][2] = m[1][2].replace('0', '9')
print(m[1][2])