I made a absolute function to print absolute values in python programming but its not returning values that what i expected.
l1=[1,2,3,4,5,-1,-5,-9,10]
def absolute(x):
if x>=0:
return x
else:
return -x
print(sorted(l1, key=absolute))
output: [1, -1, 2, 3, 4, 5, -5, -9, 10] Expected Output: [1, 1, 2, 3, 4, 5, 5, 9, 10]
Please help me fast if any can??