This question has already been answered:

Suppose there are two lists:

a=["Andrei","Oleg","Vadim","Vladimir"] b=[4,2,1,3] 

I can’t figure out how to sort on list b in order to place names in list a accordingly, and in the end it turned out:

 a=["Vadim","Oleg","Vladimir","Andrei"] b=[1,2,3,4] 

Reported as a duplicate by jfs python Jan 23 '17 at 3:26 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • do a sorting function and drive two arrays there one after another - Paulo Berezini
  • Use hashmap - Paulo Berezini

2 answers 2

If I understand the question correctly, there is an option to do this:

 a=["Andrei","Oleg","Vadim","Vladimir"] b=[4,2,1,3] a.sort() b.sort() 
  • It is just sorting two lists separately. The author seems to want to sort them out as tuples by the second element. - Nick Volynkin
 [z[1] for z in sorted(zip(b, a))]