I have a rather simple question and I have found several answers to this question but I simply can’t get my head around it.
I have a list of x-values (for a plot) and a equally long list of y-values. I want to sort the list of y-values and update my x-list accordingly.
Suppose I have these lists
xVars = [1,2,3,4,5]
yVars = [9,7,1,3,5]
After sorting this is the result I want:
xVars = [3,4,5,2,1]
yVars = [1,3,5,7,9] #this is now sorted
My point in doing this is that I want to plot the max y-values with the associated x-values.
I have encountered the itemgetter() function and the sorted(key=) but I understand neither (that is, they don’t work but thatś rather due to me not understanding them than it is because they wouldn’t work).
Many Thanks in advance!
EDIT: Many Thanks to all of you, I wish I could chose all of you as the correct answer but unfortunately I can. Your explanations have been very helpful and I have learned quite a bit more about python now. Thanks! 🙂
1 Answer