Sorting Multidimesional array(newbie)
Matimus
mccredie at gmail.com
Mon Dec 11 13:58:29 EST 2006
Tartifola wrote:
> Hi,
> how can I sort an array like
>
> array([[5, 2],
> [1, 3]])
>
> along the first column to obtain
>
> array([[1, 3],
> [5, 2]])
> i.e. keeping track of the ordered couples?
>
> Thanks,
> A
use a sort key:
>>>from operators import getitem
>>>a = [[5,2],[1,3]]
>>>a
[[5, 2], [1, 3]]
>>>a.sort(key=lambda x:getitem(x,0))
>>>a
[[1, 3], [5, 2]]
More information about the Python-list
mailing list