0
How would you order a dictionary according to its values or keys?
For example, if you have this: dictionary = {"a":5, "c":2, "b":10} What would you do to order the dictionary according to its values or keys and giving as a result a dictionary?
4 Réponses
+ 3
By key:
for key in sorted(dictionary):
print(dictionary[key])
By value:
for key in sorted(d, key=lambda x: d[x]):
print(d[key])
+ 2
//You mean format in like ascending or descending order??
+ 1
The MUST depend on application.
The dict might show
User:XP
For a TopTenList u need order by value.
0
yes, or in alphabetic order in the case of the keys