Home > Enterprise >  Dictionary Key Values
Dictionary Key Values

Time:02-14

mydict = {"aaa":noval}

display mydict

CodePudding user response:

You want to simply take the items() of your list then sort them using the values in roles.

Roles_dict1 = {'CEO':1,'CTO':2,'Devops':3}
User_list = {'Jhon':'CEO','MATEW':'Devops','Bill':'CTO'}
user_list_items = sorted(User_list.items(), key=lambda item: Roles_dict1[item[1]])
print(dict(user_list_items))

This will give you:

{'Jhon': 'CEO', 'Bill': 'CTO', 'MATEW': 'Devops'}

If you don't see this you might have an older version of python and in that case, you might looks at collections.OrderedDict() or just leave things as a list of items.

CodePudding user response:

You don't need the first dict for the desired output, as it is equal to User_list.

  • Related