python sort list of dicts by key value code example
Example 1: sort dict by value
dict(sorted(x.items(), key=lambda item: item[1]))
Example 2: sort list of dictionaries python
unsorted_list = [{"key1":5, "key2":2}, {"key1":5, "key2":1}]
sorted_list = sorted(unsorted_list, key=lambda k: k["key2"])