I'm not sure what my problem is but it seems quite simple although I can't seem to figure it out. I have a nested dictionary:
letters = [' ', '!', '"', '%', '&', "'", '(', ')', '*', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '|', '}', '~']
count1 = 0
lettersdict = [{i : 1 for i in letters}]*len(letters)
nestedletters = {letters[i] : lettersdict[i] for i in range(len(letters)) }
... (here mapdict
is just a dictionary that maps a word in txtmatrix2[x]
to a word in trainingset[count]
and I iterate through all txtmatrix[x]
's and their corresponding trainingset[count]
)
for key in mapdict:
if len(txtmatrix[x][key]) == len(trainingset[count][mapdict[key]]):
for letnum in range(len(txtmatrix2[x][key])):
letter = txtmatrix2[x][key][letnum]
corespletter = trainingset[count][mapdict[key]][letnum]
if letter in letters:
nestedletters[letter][corespletter] += 2
sums[mapofletters[letter]] += 2
The problem is that when I run the code I want it to count the number of times a letter that appears in my object character recognition (txtmatrix2
) as for example 'a' appears in my gold standard(trainingset
as 'a','b','c'...). However when I run this code, it seems as if instead of updating the dictionary associated with nestedletters['a']['a']
it updates nestedletters[j for j in letters]['a']
(ie it updates the 'a' slot for all dictionaries corresponding to 'a'...'Z'). Curious if someone has any ideas with what is going on.
Cameron