Home > other >  how to select the maximum value keyframe from the python dictionary
how to select the maximum value keyframe from the python dictionary

Time:06-14

I have python dictionary as follows;

betweeness = {'1': 0.0, '2': 0.0, '3': 0.012383661306863258, '5': 0.2325097571925996, '9': 0.021426274633144952, '13': 0.0, '51': 0.020636786004927934, '58': 0.0, '101': 0.050549206468619164}

what is the easiest method to select the maximum value generated keyframe from the above dictionary, (i.e., keyframe = '5' as per the above dictionary)

CodePudding user response:

Using max

print(max(betweeness, key=lambda x: betweeness[x]))

CodePudding user response:

data = {'1': 0.0, '2': 0.0, '3': 0.012383661306863258, '5': 0.2325097571925996, '9': 0.021426274633144952, '13': 0.0, '51': 0.020636786004927934, '58': 0.0, '101': 0.050549206468619164}
print(max(data, key = data.get))
  • Related