I have an array of names and an array of votes, the arrays are matching index's. If I sort the votes in descending order then how do I sort the names the same way?
Asked
Active
Viewed 30 times
1
-
Can't you use dictionary instead of lists? Then use sorted function with values method. – Chintan Patel May 16 '18 at 08:31
-
1`sorted(zip(list1, list2))` – jspcal May 16 '18 at 08:34
-
BTW, keeping two lists in parallel is not fun. I suggest uniting them in some way, eg create a list of tuples. Some of the answers in the linked question show how to do that using `zip` as part of their sorting procedure. – PM 2Ring May 16 '18 at 08:34
-
@jspcal, it won't work, if votes are in `list2` – akshat May 16 '18 at 08:37
-
No @akshat, it is the answer. – jspcal May 16 '18 at 09:08