Respuesta :
The groups_per_user function receives a dictionary, which contains group names with the list of users.
Explanation:
The blanks to return a dictionary with the users as keys and a list of their groups as values is shown below :
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] = user_groups.get(user,[]) + [group]
return(user_groups)
print(groups_per_user({"local": ["admin", "userA"],
"public": ["admin", "userB"],
"administrator": ["admin"] }))
The missing statements in the program are:
- for group,users in group_dictionary.items():
- for user in users:
- user_groups[user] = user_groups.get(user,[]) + [group]
The first missing instruction is to iterate through the group_dictionary.
To do this, we make use of the following enhanced for loop:
for group,users in group_dictionary.items():
The above statement would iterate through the keys and the values of the dictionary.
The next missing statement is to iterate through the values in users list
To do this, we make use of the following enhanced for loop:
for user in users:
Lastly, the group is added to the user list using:
user_groups[user] = user_groups.get(user,[]) + [group]
Read more about dictionary and lists at:
https://brainly.com/question/14353514