Recently tried something similar to PHP get largest number from 3 variables
(In Python's form of course) However when returning the value I get the value of the variable, not the name of the variable.
My array looks like this:
x = 1
y = 2
z = 3
alloutputs = [x, y, z]
The furthest and most ugliest before needing help is this:
alloutputs[alloutputs.index(max(alloutputs))]
However it's still giving me an integer of the highest value! How would I get back the name of x, y, or z depending on which is largest?
As @zhangxaochen says, you need to use a dictionary or named tuple. You could use a dictionary like this:
>>> d = {'x': 1, 'y': 2, 'z': 3}
>>> max(d, key=d.get)
'z'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With