Home > Enterprise >  Dictionary KEYS python
Dictionary KEYS python

Time:02-14



for key in Roles_dict1.keys:

Thanks in Advance

CodePudding user response:

Try the following.

Roles_dict1 = {'CEO':1,'CTO':2,'Devops':3}
User_list = {'Jhon':'CEO','MATEW':'Devops','Bill':'CTO'}

print(sorted(User_list.items(), key=lambda x:Roles_dict1[x[1]]))

Result:

[('Jhon', 'CEO'), ('Bill', 'CTO'), ('MATEW', 'Devops')]

You can cast this as a dictionary by applying dict(...) to the resulting list.

CodePudding user response:

Should be Roles_dict1.keys() rather than Roles_dict1.keys.

  • Related