sorting "problem"
Mike C. Fletcher
mcfletch at rogers.com
Tue Nov 4 10:15:06 EST 2003
Gary Herron wrote:
>On Tuesday 04 November 2003 01:48 am, Bror Johansson wrote:
>
>
>>Assume having defined two lists. There will be a one-to-one relationship
>>between elements in the two lists.
>>
>>Is there a way to - when calling listA.sort() - have elements in listB
>>shuffled the same as those in listA? When calling listB.sort(), the listA
>>should be sorted alikewise.
>>
>>
You can use the Numeric Python extensions for this if you've got a lot
of elements:
>>> from Numeric import *
>>> a
array([8, 5, 1, 4, 3])
>>> b
array([5, 2, 9, 8, 7])
>>> indices = argsort(a)
>>> indices
array([2, 4, 3, 1, 0])
>>> c,d = take(a,indices),take(b,indices)
>>> c
array([1, 3, 4, 5, 8])
>>> d
array([9, 7, 8, 2, 5])
Enjoy,
Mike
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
More information about the Python-list
mailing list