Sorry for the bad title wording, didn't know how to explain it. What I want to do here is itarate over the dictionary given as a parameter. I then return a new dictionary that grabs the list value from a key and creates a list of the keys in the PREVIOUS dictionary that contained the value. At the moment, I cannot figure it out.
Thank you for any help!
def groups_per_user(group_dictionary):
user_groups = {}
# Go through group_dictionary
for group, users in group_dictionary.items():
# Now go through the users in the group
for user in users:
# Now add the group to the the list of
# groups for this user, creating the entry
# in the dictionary if necessary
user_groups[user] = [group for user in group_dictionary]
return(user_groups)
print(groups_per_user({"local": ["admin", "userA"],
"public": ["admin", "userB"],
"administrator": ["admin"] }))
# Expected output: {'admin':['local','public','administrator'], 'userA':['local', 'userB':['public']}