With Python 3.6, what's the most efficient way to transform this dictionary into a List? I've tried to use a lot of loops, but it doesn't look efficient at all, it takes some time. This is the original dictionary:
d = {'Owner': [{'login': 'AAAA', 'mail': '[email protected]'},
{'login': 'BBBB', 'mail': '[email protected]'},
{'login': 'CCCC', 'mail': '[email protected]'}],
'Stakeholder': [{'login': 'DDDD', 'mail': '[email protected]'},
{'login': 'AAAA', 'mail': '[email protected]'}],
'Team': [{'login': 'CCCC', 'mail': '[email protected]'},
{'login': 'BBBB', 'mail': '[email protected]'}]}
This is the goal:
[{'login': 'AAAA', 'mail': '[email protected]', 'roles': ['Owner', 'Stakeholder']},
{'login': 'BBBB', 'mail': '[email protected]', 'roles': ['Owner', 'Team']},
{'login': 'CCCC', 'mail': '[email protected]', 'roles': ['Owner', 'Team']},
{'login': 'DDDD', 'mail': '[email protected]', 'roles': ['Stakeholder']}]
Thanks!
Edit 1: So far I could get a list of unique users:
list_users = []
for role, users in old_dict.items():
for user in users:
list_users.append(user)
unique_list_of_users = []
for i in range(len(list_users)):
if list_users[i] not in list_users[i + 1:]:
unique_list_of_users.append(list_users[i])
for user in unique_list_of_users:
user["role"] = []