Discuss / Python / 其实sorted函数还有个参数cmp

其实sorted函数还有个参数cmp

Topic source

LikeABird_CX

#1 Created at ... [Delete] [Delete and Lock User]
# 1.
sorted(L, cmp=lambda x,y: cmp(x[0].lower(), y[0].lower()))


# 2.
sorted(L, cmp=lambda x,y: cmp(x[1], y[1]), reverse=True)

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

那是2.7版本的


  • 1

Reply