With the following
Code
arr = [{"name":"joe", "hotdogs":5},{"name":"april", "hotdogs":5},{"name":"ryan", "hot dogs":8}]
How to in python sort the elements of the array such as the dicts are sorted by name?
arr = [{"name":"april", "hotdogs":5},{"name":"joe", "hotdogs":5},{"name":"ryan", "hotdogs":8}]
How to apply some function to sort the dicts in the array?
Like this:
arr.sort(key=operator.itemgetter('name'))
Have a look at the following web page: http://wiki.python.org/moin/HowTo/Sorting/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With