Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alphabetically sort array of dictionaries on single key?

I want to sort the list of friends returned by Facebook's Graph API. The result after sorting needs to be an alphabetical order of friends by name.

[
      {
         "name": "Joe Smith",
         "id": "6500000"
      },
      {
         "name": "Andrew Smith",
         "id": "82000"
      },
      {
         "name": "Dora Smith",
         "id": "97000000"
      },
      {
         "name": "Jacki Smith",
         "id": "107000"
      }
]

Additional notes: I am running on Google App Engine, which uses Python 2.5.x.

like image 432
Will Curran Avatar asked Feb 19 '11 04:02

Will Curran


1 Answers

sorted(flist, key=lambda friend: friend["name"])
like image 167
MHC Avatar answered Oct 06 '22 19:10

MHC