I want to sort a list of dictionaries.
The problem is that key in the dictionaries are not same, but every dictionary will have only one item for sure.
For example, [{'foo':39}, {'bar':7}, {'spam':35}, {'buzz':4}]
Here, key is the name of the person and value is the age.
I want result as [{'buzz': 4}, {'bar': 7}, {'spam': 35}, {'foo': 39}]
What I am doing is :
def get_val(d):
for k, v in d.items():
return v
sorted_lst = sorted(lst, key=lambda d: get_val(d))
Is there any better solution?