Sorting a list of dicts by dict values

dictionary, list, python, sorting

Solution

In addition to brandizzi's answer, you could go with:

sorted(a, key=dict.values, reverse=True)

Pretty much the same thing, but possibly more idiomatic.

Problem

I have the following list of dictionaries ``` a = [{23:100}, {3:103}, {2:102}, {36:103}, {43:123}] ``` How can I sort it to get: ``` a = [{43:123}, {3:103}, {36:103}, {2:102}, {23:100}] ``` I mean, to sort the list by its dicts' values, in descending order.

Original source