Getting sorting order
__peter__ at web.de
Mon Jun 30 12:06:53 CEST 2008
>> Or provide a better explanation and an example. Do you mean something
>> like this?
> Hi Peter,
> a small example:
> master.sort() # this is ok, but does not return infos on how the list
> was sorted
> Then I should get:
> Hope it is more clear now.
> Thanks, leodp
You need a helper list (called master_index in the example below):
>>> master_index = range(len(master))
>>> master[:] = [master[i] for i in master_index]
>>> slave1[:] = [slave1[i] for i in master_index]
>>> slave2[:] = [slave2[i] for i in master_index]
[1, 2, 3, 4]
['d', 'a', 'b', 'c']
[1, 4, 3, 2]
If you don't care about list object identity you can use
master = [...] instead of master[:] = [...] etc.
More information about the Python-list