Blog Archive for October 5, 2012

Sorting an Array of Dictionaries by key

October 5, 2012

I had an array of dictionaries in Python, and wanted to sort by one element of the dictionary.

So, given:

lToSort = [
    {'name':'Delbert'},
    {'name':'Becky'},
    {'name':'Albert'},
    {'name':'Chris'},
]

I wanted to get back:

lSorted …