I've made a dictionary in Python that's composed of 4 lists as values, with a single letter key for each list. When I try to change a value in only one of the lists by referencing dict_name[key][list index], I'm finding that that same index is changing in the lists for every one of the keys in the dictionary.
Here's an example of the starting dictionary:
my_dict = {'A': [0, 0, 0, 0], 'C': [0, 0, 0, 0], 'G': [0, 0, 0, 0], 'T': [0, 0, 0, 0]}
And then I try to change a single value in one of the lists by iterating with a for-loop:
test_string = 'WXTZ'
k = len(test_string)
for i in range(k):
if test_string[i] == 'T':
my_dict['T'][i] += 1
But the output I'm getting doesn't make sense:
print(my_dict) = {'A': [0, 0, 1, 0], 'C': [0, 0, 1, 0], 'G': [0, 0, 1, 0], 'T': [0, 0, 1, 0]}
I would think that this should return the following instead:
print(my_dict) = {'A': [0, 0, 0, 0], 'C': [0, 0, 0, 0], 'G': [0, 0, 0, 0], 'T': [0, 0, 1, 0]}
Has anyone else experienced something like this before? How would I change only the 'T' list in this case with such a loop, if not this way?
I'm in Python 3 with Atom on Windows 10 if that's worth knowing. Thanks!
EDIT: A few of you asked about the code that I used to create my_dict. Including that below for reference:
holder = []
my_dict = {}
k = len(string)
for i in range(k):
holder.append(0)
for char in 'ACGT':
my_dict[char] = holder