Returns a new tuple subclass named typename. The new subclass is used to create tuple-like objects that have fields accessible by attribute lookup as well as being indexable and iterable. Instances of the subclass also have a helpful docstring (with typename and field_names) and a helpful repr() method which lists the tuple contents in a name=value format.
对不起,如果我误解了你的问题。我不太明白。在
所以,我假设你想按列排序
假设x是二维数组
下面是一种使用itemgetter按每列进行排序的方法
^{pr2}$如果您想要就地排序,请按
x.sort(key=itemgetter(0))
考虑使用
namedtuple
来创建对象。(看看is-there-a-tuple-data-structure-in-python。)具有
A B C
字段名的简单交互式会话。排序很简单key=lambda o:o.A
:相关问题 更多 >
编程相关推荐