I've written some code, but it does not output what I expected.
Here is the code:
query_words = ['probabilistic']
query_word_to_synonym_dict = {'probabilistic': ['probabilistic', 'algorithms']}
mail_ids = {83, 108}
big_ds = {}
empty_dict = {}
index = {'probabilistic':{(108, 1)}, 'algorithms':{(83, 1)}}
for query_word in query_words:
empty_dict.update({query_word:[]})
for mail_id in mail_ids:
big_ds.update({mail_id:empty_dict})
for query_word in query_words:
syns = query_word_to_synonym_dict[query_word]
for syn in syns:
index_of_word = index[syn]
tuple_first = []
for tuples in index_of_word:
tuple_first.append(tuples[0])
for number in tuple_first:
(big_ds[number][query_word]).append(syn)
print(big_ds)
The expected final value of big_ds
is:
{83: {'probabilistic': ['algorithms']}, 108: {'probabilistic': ['probabilistic']}}
But the code sets the value of big_ds
to the following:
{83: {'probabilistic': ['probabilistic', 'algorithms']}, 108: {'probabilistic': ['probabilistic', 'algorithms']}}
I tried debugging, and I know that the error has something to do with this line:
(big_ds[number][query_word]).append(syn)
But I can't seem to figure out how to fix things. Any solution?