How do I sort a list of dictionaries by a value of the dictionary?
Asked 07 September, 2021
Viewed 1K times
  • 60
Votes

I have a list of dictionaries and want each item to be sorted by a specific value.

Take into consideration the list:

[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]

When sorted by name, it should become:

[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}]

18 Answer