How to find the maximum variable in a list in python
MikeJMS8910

So here is my code -

var1 = 1
var2 = 2
var3 = 3
varList = [var1, var2, var3]

I want to find which variable has the highest value but then get the variable. This means that I can't use max because the value would be 3 instead of var3, but I want var3.

You are viewing a single comment. View All
RYANTADIPARTHI

Solution

try this code.

like that.
That should work

MikeJMS8910

@RYANTADIPARTHI yes I tried this but then got an error which was like index out of range

RYANTADIPARTHI

@MikeJMS8910 can i see your code?

MikeJMS8910

@RYANTADIPARTHI ok heres the code - https://repl.it/@MikeJMS8910/Machine-Learning#main.py - the part that I am working in is line 125

RYANTADIPARTHI

@MikeJMS8910 maybe remove the [0] from the end.

MikeJMS8910

@RYANTADIPARTHI ok ill try that

MikeJMS8910

@RYANTADIPARTHI ok I did it but now there are no errors but the max value keeps coming out as []