Jan-28-2018, 03:36 PM
I am trying to understand how to sort an array in Python 3.x using the bulit in sort function. So I wrote the following code. However, it did does not work.
Bob
a = [1,-2,3,-4,5,-6] sorted(a, cmp = numeric_compare )where numeric_compare is defined as follows:
def numeric_compare(x, y): return abs(x) - abs(y)What I want to do is sort the array by the absolute values of the numbers. I realize, in this case the array is already sorted in that order.
Bob