I have a list of words that I want to organize in a dictionary according to the content of another list:
group_identifier = [1,2,1]
word_list = ['a', 'big', 'problem']
word_dict = dict.fromkeys([x for x in group_identifier], {'words': []})
for word, group in zip(word_list, group_identifier):
word_dict[group]['words'].append(word)
print(word_dict)
I would like to get:
{1: {'words': ['a', 'problem']}, 2: {'words': ['big']}}
,
but I get:
{1: {'words': ['a', 'big', 'problem']}, 2: {'words': ['a', 'big', 'problem']}}
Help would be greatly appreciated!