I have 2 dictionaries:
S = {0: [1, 2, 3, 4],
1: [5, 6, 7, 8, 9, 10],
2: [11, 12, 13, 14, 15]}
R = {0: [1, 2, 8],
1: [8, 5, 10, 11, 15],
2: []}
I need to find out for a given key if any of the numbers in the list match. If they do then replace the numbers with 'X'.
The result should look like this
F = {0: ['X', 'X', 3, 4],
1: ['X', 6, 7, 8, 9, 'X'],
2: [11, 12, 13, 14, 15]}
or
F = [['X', 'X', 3, 4], ['X', 6, 7, 8, 9, 'X'], [11, 12, 13, 14, 15]]
I'm indifferent if F is a 3rd dictionary or a list of lists.
My code is as follows:
Solution = []
for x in S.values():
for y in R.values():
for j in y:
for n, i in enumerate(x):
if j == i:
x[n] = 'X'
Solution.append(x)
The problem is that I'm comparing every value in R to each dictionary value in S. I'm not understanding how to compare for example [1, 2, 3, 4] to [1, 2, 8] independently of [5, 6, 7, 8, 9, 10] to [8, 5, 10, 11, 15].