. 1 Li = [{ ' A ' :. 1, ' B ' :. 4}, { ' A ' : 2, ' B ' :. 3}, { ' A ' :. 3, ' B ' : 2}, { ' A ' :. 4, ' B ' :. 1 }] 2 Print ( ' Li ' , Li) . 3 # the value of a reverse order . 4 LINEW the sorted = (Li, Key = the lambda E: E. the __getitem__ ( ' a '), Reverse = True) . 5 Print ( ' LINEW ' , LINEW) . 6 # The value of a reverse order . 7 liNew2 = the sorted (Li, Key = the lambda E: E [ ' a ' ], Reverse = True) . 8 Print ( ' liNew2 ' , liNew2)
The results show:
1 li [{ ' a ' : 1, ' b ' : 4}, { ' and ' 2, ' b ' : 3}, { ' a ' : 3, ' b ' : 2}, { ' a ' ; 4, ' b ' : 1 }] 2 liNew [{ ' and ' 4, ' b ' : 1}, { ' a ' : 3, ' b ' : 2}, { 'a': 2, ' b ' : 3}, { ' a ' : 1, ' b ' : 4 }] 3 LiNew2 [{ ' a ' : 4, ' b ' : 1}, { ' a ' : 3, ' b ' : 2}, { ' a ' : 2, ' b ' : 3}, { ' a ' : 1, ' b ' : 4}]