I have开发者_如何学Python a Multidimensional array in Python.
How do I go about sorting the second array, by the first - all the while keeping it in the same order?
I'm not sure from your answer if this is what you want, but take a look and see. If I have a multidimensional array x:
>>> x = [[100,50,39,69,22,23,19,80,94,72],range(10)]
>>> print x
[[100, 50, 39, 69, 22, 23, 19, 80, 94, 72], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
and I want to sort the second subarray by the first subarray, I could do the following:
>>> x[1].sort(key = x[0].__getitem__)
>>> print x
[[100, 50, 39, 69, 22, 23, 19, 80, 94, 72], [6, 4, 5, 2, 1, 3, 9, 7, 8, 0]]
Is that what you're looking for?
精彩评论