Ask Question
Yesterday, 17:42

The groups_per_user function receives a dictionary, which contains group names with the list of users. Users can belong to multiple groups. Fill in the blanks to return a dictionary with the users as keys and a list of their groups as values.

def groups_per_user (group_dictionary):

user_groups = {}

# Go through group_dictionary

for ___:

# Now go through the users in the group

for ___: # Now add the group to the the list of

# groups for this user, creating the entry

# in the dictionary if necessary

return (user_groups)

print (groups_per_user ({"local": ["admin", "userA"],

"public": ["admin", "userB"],

"administrator": ["admin"] }))

+4
Answers (1)
  1. Yesterday, 19:01
    0
    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"] }))
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “The groups_per_user function receives a dictionary, which contains group names with the list of users. Users can belong to multiple groups. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers