摘要:
下文讲述Python中数组的排序方法分享,如下所示;
实现思路: 一维数组可使用sort函数进行排序操作 多维数组可使用sort函数和lambda匿名函数进行排序操作
例:
Python 数组排序的示例分享
#maomao365.com #Python 数组排序的示例分享 #一维数组的排序 arr1 =[88,1,99,10,100]; arr1.sort(); print(arr1); #多维数组的排序 arr2 = [['maomao', 88], ['linux',1], ['other', 99], ['365', 10]] arr2.sort(key=lambda x:x[1],reverse=False) print(arr2) //输出 [1, 10, 88, 99, 100] [['linux', 1], ['365', 10], ['maomao', 88], ['other', 99]]