groups_per_user 函数接收一个字典,其中包含组名称和用户列表。用户可以属于多个组。填写空白以返回一个字典,其中用户作为键,其组列表作为值
def groups_per_user(group_dictionary):
user_groups = {}
for key,values in group_dictionary.items():
for users in values:
user_groups[users] = user_groups.get(users,0)+1
return(user_groups)
print(groups_per_user({"local": ["admin", "userA"],"public": ["admin", "userB"],"administrator": ["admin"] }))
# output must be {'admin':["local","public","administrator"],'userA':"local" ,'userB':"public"}
#output I am getting {'admin': 3, 'userA': 1, 'userB': 1}
慕森王
Qyouu
相关分类