Search code examples
pythonlistmax

How to print out the item of a list when its corresponding value in another list is the biggest?


If I have 2 lists:

values = ['a', 'b', 'c', 'd']
accuracies = [1, 2, 3, 4]

I want to return the value in values when its corresponding accuracy in accuracies is the biggest. In this case, the result of value should be 'd', because its corresponding accuracy is 4. Is there a way to do it in python? Thank you in advance.


Solution

  • Use this:

    In [5]: values[accuracies.index(max(accuracies))]
    Out[5]: 'd'