首页 > 编程知识 正文

python输入二维数组,python有二维数组吗

时间:2023-05-06 18:43:52 阅读:34696 作者:4391

I have 2d array,dimension 3x10,and I want to sort by values in 2nd row,from lowest to highest value。

解决方案

soi ' llassumethatby ' 2d阵列' youmeanalistoflists,such as:

lol=[范围(10 )、范围(12 )、范围(15 ) ]

or the like -- i.e. a list with 3 items,each item being a list with 10 items,and the ' second row ' wouldbethesublistitemlol [1]. butyourquestionissomaddeninglyvaguethatthere ' snowaytoavoidmakingassumptions-edityourqtoclarifywithmore、ifyoudislikepepeopoplptiore

soundertheseassumptionsyoucansorteachofthe3sublistsintheorderrequiredtosortthesecondone,for example:

索引=范围(10 )。

indices.sort (key=lol [1]._ _ getitem _ ) )

for i,sublistinenumerate(lol ) :

thegeneralapproachereistosorttherangeofindices,thenjustusethatappropriatelysortedrangetoreorderallthesubliststsinplay。

ifyouactuallyhaveadifferentproblem,therewillofcoursebedifferentsolutions; - )。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。