【发布时间】:2018-02-25 20:21:57
【问题描述】:
根据列表中的第一个列表对列表嵌套进行排序的最佳方法是什么?
排序前
>>> list_of_things = [[100,300,200],[t,u,v]]
排序后
>>> [[100,200,300],[t,v,u]]
到目前为止,我使用搜索找到了一个可以用来排序的索引
>>> import numpy as np
>>> sort_index=np.argsort(list_of_things[0])
但我还没有找到一种 Python 方法来索引 sort_index 上的两个子列表。
有什么想法吗? 谢谢!
【问题讨论】:
-
您想根据 list[0] 的 argsorted 值对 list[1:n] 进行排序吗?
标签: python arrays list sorting numpy