Sorting by absolute value without changing to absolute value

后端 未结 3 433
滥情空心
滥情空心 2020-12-06 12:07

I want to sort a tuple using abs() without actually changing the elements of the tuple to positive values.

def sorting(numbers_array):
    return sorted(numb         


        
3条回答
  •  醉酒成梦
    2020-12-06 12:46

    lst = [-1, 1, -2, 20, -30, 10]
    >>>print(sorted(lst, key=abs))
    >>>[-1, 1, -2, 10, 20, -30]
    

提交回复
热议问题