lamda 表达式的意义
# 需求:将列表中的元素按其平方进行排列
li = [3,5,-4,-1,0,-2,-6]
sorted(li, key=lambda x: x^2)
当然,也可以如下:
li1 = [3,5,-4,-1,0,-2,-6]
def get_square(x):
return (x^2)
sorted(list1,key=get_square)
充分显示了其 PEP
Explicit is better than implicit
的特点
“Talk is cheap. Show me the code.”
–Linus Torvalds