简体   繁体   English

根据第 0 个索引处的项目对 2D 嵌套列表进行排序

[英]Sort 2D nested list based on item at 0th index

I have a 2D list as follow:我有一个二维列表如下:

[['0', '1', '16', '35'], ['3', '41', '80', '58'], ['2', '14', '84', '90'], ['1', '14', '108', '113'], ['8', '129', '147', '38']]

I want to sort this 2D list based on 1st column (0th index) of each element like:我想根据每个元素的第一列(第 0 个索引)对这个 2D 列表进行排序,例如:

[['0', '1', '16', '35'],['1', '14', '108', '113'],['2', '14', '84', '90'],
['3', '41', '80', '58'],['8', '129', '147', '38']]

I have a 2D list as follow:我有一个二维列表如下:

[['0', '1', '16', '35'], ['3', '41', '80', '58'], ['2', '14', '84', '90'], ['1', '14', '108', '113'], ['8', '129', '147', '38']]

I want to sort this 2D list based on 1st column (0th index) of each element like:我想根据每个元素的第一列(第 0 个索引)对这个 2D 列表进行排序,例如:

[['0', '1', '16', '35'],['1', '14', '108', '113'],['2', '14', '84', '90'],
['3', '41', '80', '58'],['8', '129', '147', '38']]

I have a 2D list as follow:我有一个二维列表如下:

[['0', '1', '16', '35'], ['3', '41', '80', '58'], ['2', '14', '84', '90'], ['1', '14', '108', '113'], ['8', '129', '147', '38']]

I want to sort this 2D list based on 1st column (0th index) of each element like:我想根据每个元素的第一列(第 0 个索引)对这个 2D 列表进行排序,例如:

[['0', '1', '16', '35'],['1', '14', '108', '113'],['2', '14', '84', '90'],
['3', '41', '80', '58'],['8', '129', '147', '38']]

I have a 2D list as follow:我有一个二维列表如下:

[['0', '1', '16', '35'], ['3', '41', '80', '58'], ['2', '14', '84', '90'], ['1', '14', '108', '113'], ['8', '129', '147', '38']]

I want to sort this 2D list based on 1st column (0th index) of each element like:我想根据每个元素的第一列(第 0 个索引)对这个 2D 列表进行排序,例如:

[['0', '1', '16', '35'],['1', '14', '108', '113'],['2', '14', '84', '90'],
['3', '41', '80', '58'],['8', '129', '147', '38']]

I have a 2D list as follow:我有一个二维列表如下:

[['0', '1', '16', '35'], ['3', '41', '80', '58'], ['2', '14', '84', '90'], ['1', '14', '108', '113'], ['8', '129', '147', '38']]

I want to sort this 2D list based on 1st column (0th index) of each element like:我想根据每个元素的第一列(第 0 个索引)对这个 2D 列表进行排序,例如:

[['0', '1', '16', '35'],['1', '14', '108', '113'],['2', '14', '84', '90'],
['3', '41', '80', '58'],['8', '129', '147', '38']]

I have a 2D list as follow:我有一个二维列表如下:

[['0', '1', '16', '35'], ['3', '41', '80', '58'], ['2', '14', '84', '90'], ['1', '14', '108', '113'], ['8', '129', '147', '38']]

I want to sort this 2D list based on 1st column (0th index) of each element like:我想根据每个元素的第一列(第 0 个索引)对这个 2D 列表进行排序,例如:

[['0', '1', '16', '35'],['1', '14', '108', '113'],['2', '14', '84', '90'],
['3', '41', '80', '58'],['8', '129', '147', '38']]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据第0个列表的argsort对嵌套列表中的列表进行排序 - Sort lists in a nested list based on the argsort of the 0th list 如何基于第0列中的字符串将嵌套列表(用作矩阵)细分为列表 - How to subdivide a nested list (used as a matrix) into lists based on the string in the 0th column 根据索引值搜索二维嵌套列表 - Searching a 2D nested list based on index value 在具有 2D 索引的 2D 列表中查找(子)项的索引 - Find index of an (sub)item in a 2D list with a 2D index 如何从 tensorflow 中的 2d boolean 掩码沿第 0 轴找到“下一个”值 - How to find "next" value along 0th axis from 2d boolean mask in tensorflow 基于我如何使用Python对2D列表行进行排序的方式对2D列表进行排序 - Sort 2D list based on how I sort another 2D list rows with Python BerTopic Model - 可视化忽略第 0 个索引 - BerTopic Model - Visualization ignores 0th index 如何有效地比较字典中列表中的项目与第二个字典中另一个列表中的第0个项目 - How to efficiently compare the items in a list within a dictionary to the 0th item within another list within a second dictionary Python:对 2d ndarray 进行排序并返回元组中的索引列表 - Python: Sort 2d ndarray and return a list of index in tuples 检查二维列表的索引并根据二维列表打印出索引 - Check index for 2D list and print out the index based on 2D list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM