The A cmp function should return a negative or positive number to indicate which element should go first (if they are not equal, then return 0). The function cmp y > x will only return 0 or 1 . Try changing it to the following:
lista.sort(cmp=lambda x,y: (y > x) - (y < x))
I took this from the Python 3 docs :
If you really need cmp() functionality, you can use the expression (a > b) - (a < b) as the equivalent for cmp(a, b) .
source share