That data structure you're using is not a list
it's a dictionary
where values are lists
.
To get what you want you'd have to this:
d = {1:["O","O","O","O","O"],2:[1,2,3,4,5],3:["a", "b", "c", "d"]}
d[1] = [i.replace("O", "X") for i in d[1]]
print(d)
{1: ['X', 'X', 'X', 'X', 'X'], 2: [1, 2, 3, 4, 5], 3: ['a', 'b', 'c', 'd']}
Or you could iterate over the dictionary
items and check if the list
contains all strings and the character you want to replace:
old = "O"
new = "X"
d = {1:["O","O","O","O","O"],2:[1,2,3,4,5],3:["a", "b", "c", "d"]}
for key, value in d.items():
if all(isinstance(item, str) for item in value) and old in value:
d[key] = [item.replace(old, new) for item in d[key]]
print(d)
Output: {1: ['X', 'X', 'X', 'X', 'X'], 2: [1, 2, 3, 4, 5], 3: ['a', 'b', 'c', 'd']}