I have a list of objects and for each object I calculated a corresponding function value, which I stored in another list. Now I want to sort both the lists according to this function value. I tried applying something I found at Sorting list based on values from another list? but that doesn't seem to work because '<' is not supported for an object (that's what the error says). In case it matters: several objects can have the same function value assigned to them.
For one of my attempts to solve this I tried using the code bellow but this gives a strange result. The list that is printed is [9, 8, 7, 0, 6, 5, 1, 2, 3, 4] and I do not see the logic behind this. Why doesn't this output [3,6,7,8,5,4,2,1,0]?
ranking = list(range(10))
test = [10,40,80,90,100,20,11,5,3,2]
print(sorted(ranking, key = lambda x: test[x]))