Choose Variable With Highest Value (Python)
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
Solution 1:
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.
Post a Comment for "Choose Variable With Highest Value (Python)"