listOfDict = [{"sal":1000,"age":25},{"sal":1000,"age":24}, {"sal":1000,"age":26},{"sal":2000,"age":25},{"sal":3000,"age":24}]
Expected o/p : [{"sal":3000,"age":24}, {"sal":2000,"age":25}, {"sal":1000,"age":24}, {"sal":1000,"age":25},{"sal":1000,"age":26}]
I want to sort this in decreasing order of salary and increasing order of age.
I tried c++ style like this:
def auxsort(p1data, p2data):
if p1data['sal'] > p2data['sal']:
return True
if p1data['age'] <= p2data['age']:
return True
return False
sorted(listOfDict,key=auxsort)
But this is not allowed in python. TypeError: auxsort() takes exactly 2 arguments (1 given)
How to solve this? Thank you