I have a nested list:
a = [[{'aa': 2L}, {}, {'mm': 9L}, {}, {}], [{'aa': 1L}, {}, {'mm': 5L}, {}, {}], [{'aa': 2L}, {}, {'mm': 7L}, {}, {}], [{'aa': 5L}, {}, {'mm': 7L}, {}, {}]]
Desired Output:
a = [[{'aa': 1L}, {}, {'mm': 5L}, {}, {}], [{'aa': 2L}, {}, {'mm': 7L}, {}, {}], [{'aa': 5L}, {}, {'mm': 7L}, {}, {}], [{'aa': 2L}, {}, {'mm': 9L}, {}, {}]]
Output I am getting from a.sort() :
a = [[{'aa': 1L}, {}, {'mm': 5L}, {}, {}], [{'aa': 2L}, {}, {'mm': 7L}, {}, {}], [{'aa': 2L}, {}, {'mm': 9L}, {}, {}], [{'aa': 5L}, {}, {'mm': 7L}, {}, {}]]
Not desired.
Here I want to sort the list 'a' by considering any one of the keys of child lists.In this case I am using third dictionary and key 'mm'.Right now there is only one key 'mm' there may be multiple key value pairs but I should be able to avoid others and do the sorting on the basis of 'mm' keys value only.
a.sort()output are same(except for some missing whitespaces in desired output!)