Getting sorting order
Hi all, I cannot find anything on this: I have a few lists, and would like to sort one of them (sorting-master list). Then I would like to sort all other lists according to how the first one was sorted (sorting-slave lists). Is there a standard way to do that? >From what I know sort() and sorted() do not return the order of sorting. Maybe I have to write some more code. Ciao, leodp -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting sorting order
> Or provide a better explanation and an example. Do you mean something like > this? > Hi Peter, a small example: master=[1,4,3,2] slave1=['d','c','b','a'] slave2=[1,2,3,4] master.sort() # this is ok, but does not return infos on how the list was sorted slave1.sort(key=_maybe_something_here_referring_to_master_) slave2.sort(key=_maybe_something_here_referring_to_master_) Then I should get: master=[1,2,3,4] slave1=['d','a','b','c'] slave2=[1,4,3,2] Hope it is more clear now. Thanks, leodp -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting sorting order
> >>> master_index.sort(key=master.__getitem__) that was it! Thanks Peter, leodp -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting sorting order
> >>> x=zip(master,slave1,slave2) > >>> x.sort() > >>> master,slave1,slave2=zip(*x) > --Mark So nice is Python. Leo -- http://mail.python.org/mailman/listinfo/python-list
