l1 = [(abs(x),x) for x in l] #abs()只能有一个参数
print l1
l1.sort()
ranked=[v for (s,v) in l1]
print ranked
输出:
[(1, 1), (8, -8), (7, 7), (2, -2), (0, 0)]
[0, 1, -2, 7, -8]
print ranked
输出:
[(1, 1), (8, -8), (7, 7), (2, -2), (0, 0)]
[0, 1, -2, 7, -8]