Reputation: 35
How would I be able to replace a single index in a 2d list if we don't know what value is currently in that location?
Initially, i thought
twoDList[0][0].replace('A')
would work; however, it does not. So what is the proper way to replace an index in a 2d list in python?
Upvotes: 0
Views: 210
Reputation: 5515
.replace
does not do in place replacements since strings are immutable, rather it returns a copy of the string. make sure to set the new value to the item:
tw0dList[0][0] = 'A'
Upvotes: 1