python - How to alphabetically sort array of dictionaries on single key? -
i want sort list of friends returned facebook's graph api. result after sorting needs alphabetical order of friends name.
[ { "name": "joe smith", "id": "6500000" }, { "name": "andrew smith", "id": "82000" }, { "name": "dora smith", "id": "97000000" }, { "name": "jacki smith", "id": "107000" } ]
additional notes: running on google app engine, uses python 2.5.x.
if list called a
, can sort way using:
a.sort(cmp = lambda x,y: cmp(x["name"],y["name"]))
Comments
Post a Comment