[Tutor] Input is Dictionary1, Output is Dictionary2 (using keys and values of Dictionary1)
Panchanathan Suresh
suresh.gm at gmail.com
Thu Jan 30 15:23:47 EST 2020
Hi Everyone,
I spent a lot of time on this, trying out many things, but I am unable to
create a new dictionary with the users as keys and a list of their groups
as values.
Input Dictionary is {"local": ["admin", "userA"],"public": ["admin",
"userB"],"administrator": ["admin"] }
Expected Output Dictionary is {"userA": ["admin","public"], "userB":
["admin"], "administrator": ["admin"]}
--- How to create an unique group for a particular user?
--- And then how to add this user key and the user's value (which will be
the list of groups the user belongs to)
*****
def groups_per_user(group_dictionary):
user_groups = {}
groups = []
# Go through group_dictionary
for group,user in group_dictionary.items():
# Now go through the users in the group
for user1 in user:
groups.append(group)
print(user1,groups)
return(user_groups)
print(groups_per_user({"local": ["admin", "userA"],"public": ["admin",
"userB"],"administrator": ["admin"] }))
*****
Thanks so much
More information about the Tutor
mailing list