How do I make Python choose the variable with the hightest integer value?
E.g
a = 1
b = 2
c = 3
d = 0
I want the output to be " c". I know the max() command does something similar, but instead of choosing the variable itself, it will choose the hightest number. If I wasn't clear enough about this please tell me and I'll try and reexplain, but it seems to be a simple enough matter of not knowing the command. Thanks in advance!
This is a job for a dictionary:
data = {
'a': 1,
'b': 2,
'c': 3,
'd': 4
}
print max(data, key=data.get)
d
Python does not make a point of tracking variable names.
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