Let's say there is User object having field 'id', 'first_name', 'last_name', 'age' and so on.
I know that I need to sort according to one of the above mention property but I will only know the exact property at run time.
The thing I have tried
def sortBySomeSpecificKey(key_name):
#key_name is given to the function
Users = sorted(Users, key=lambda x: x.key_name, reverse=True)
The problem with this approach is, Instead of taking value of key_name, it is taking key_name as the property itself.
Please help.