How can I replace the following code written in python3 with normal sort() function?
list = sorted(list, key=lambda x: x['result'], reverse=True)
NOTE: x['result'] is int
How can I replace the following code written in python3 with normal sort() function?
list = sorted(list, key=lambda x: x['result'], reverse=True)
NOTE: x['result'] is int
You can do exactly the same thing using list.sort(), i.e it takes in a "key" argument,
all you have to do is to change the function call on position_list into a method call.
For example:
l.sort(key=lambda x: x["result"], reverse=True)
As far as the lambda is concerned, you can just substitute it with a real function instead, but I don't think anything else can be simpler than a lambda.
P.S: Have a look at the documentation: https://docs.python.org/3/library/stdtypes.html#list.sort