Right now, I am having troubles figuring out how to get the following output.
Desired Output:
{'Bobby': [set(), set(), set(), {'movie_2'}, set(),{'movie_1'}],
'Carren': [set(), set(), {'movie_4'}, {'movie_2'}, set(), {'movie_1'}],
'Deric': [set(), {'movie_1'}, set(), {'movie_2'}, set(),{'movie_3'}],
'Alec': [set(), {'movie_1'}, {'movie_3'}, set(), set(), {'movie_4'}] }
The dictionary I am working with:
d = {'movie_1': {('Bobby', 5), ('Carren', 5), ('Alec', 1), ('Deric', 1)},
'movie_2': {('Carren', 3), ('Deric', 3), ('Bobby', 3)},
'movie_3': {('Alec', 2), ('Deric', 5)},
'movie_4': {('Carren', 2), ('Alec', 5)} }
Inside each value, the tuple represents (person, position).
So, with dictionary d, when you look at the key 'movie_1', the first value is ('Bobby', 5).
Then the key, 'movie_1' is placed into the 5th index in the list.
The code I have so far:
I created a list with 6 items of set(), but I am not entirely sure what to do from here to get the desired output.
from collections import defaultdict
d = {
'movie_1': {('Bobby', 5), ('Carren', 5), ('Alec', 1), ('Deric', 1)},
'movie_2': {('Carren', 3), ('Deric', 3), ('Bobby', 3)},
'movie_3': {('Alec', 2), ('Deric', 5)},
'movie_4': {('Carren', 2), ('Alec', 5)},
}
def new_dict(d):
le_dict = defaultdict(set)
values = [set(), set(), set(), set(), set(), set()]
for key, value in d.items():
for person_score in value:
le_dict[person_score[0]].add(key)
return le_dict