python二维数组排序_Python排序多维数组

我需要按照特定的元素对数组进行排序。

This is an array:arr=

[0, [71, 554, 258, 793]]

[1, [61, 415, 148, 593]]

[2, [91, 145, 658, 893]]

I need to be able to sort it by arr[0][0] as well as by any element from the internal array like arr[0][1] or arr[0][2]

currently, I'm able to sort it by using key=itemgetter(1) where: itemgetter(1) - is second element of array [0, [71, 554, 258, 793]] in this cese = 71from operator import itemgetter

array = sorted(array, key=itemgetter(1))

print(*array[:], sep="\n")

how to sort this array by any element from the internal array [71, 554, 258, 793]?

so if I'm sorting by the second element from internal array output should be like this: (column 145, 415, 554)arr=

[2, [91, 145, 658, 893]]

[1, [61, 415, 148, 593]]

[0, [71, 554, 258, 793]]

如果我从内部数组输出按第三个元素进行排序,应该如下所示:(第148、258、658列)arr=

[1, [61, 415, 148, 593]]

[0, [71, 554, 258, 793]]

[2, [91, 145, 658, 893]]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值