So, I am trying to sort 2 related lists. One contains Candidate Names, and one contains the Number of Votes the candidates have (candidate in candidate[0] has votes stored in votes[0]).
I found a way to sort votes[] in descending order, whilst keeping the indexes matched. For example if vote[0] becomes vote[3], candidate[0] will also become candidate[3]. I did this using the built-in zip function, but the example I copied from sorted the lists in ascending order, whereas I require them to be sorted in descending order.
Here are my lists:
candidates = ['Donald', 'Barack', 'Hillary', 'Mitt']
votes = [9, 7, 1, 3]
And to sort the lists I used:
votes, candidates = (list(t) for t in zip(*sorted(zip(votes, candidates))))
This did exactly what I wanted, except in ascending order, not descending. How do I edit this to sort the lists into Descending order?
nestedlists, in fact aren't even listssorted(zip(votes, candidates), reverse=True)