This thread How do I sort a list of dictionaries by values of the dictionary in Python? explains very clearly how to sort a list of dictionaries. In summary for,
[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]
You do:
newlist = sorted(list_to_be_sorted, key=lambda k: k['name'])
However, I have much more elements in my dictionary and I need to sort by four of them - not just one. Any tips how to do this?
Note: I read further into the thread and this suggestion:
sortedlist = sorted(input, key=lambda elem: "%02d %s" % (elem['age'], elem['name']))
does not work. It gives error:
TypeError: list indices must be intergers, not str
I try various versions of this and to no avail.
Any help appreciated,