Skip to main content
added 68 characters in body
Source Link
Sentox
  • 950
  • 1
  • 6
  • 4

If you just want the highest value from a dict and you don't care about what key it's associated with, you can just do:

max_value = max(d.values())

For the key of the max value:

max_key = max(d, key=d.get)

If you want both in a pair:

max_tuple = max(d.items(), key=lambda k: k[1])

If you just want the highest value from a dict and you don't care about what key it's associated with, you can just do:

max_value = max(d.values())

If you just want the highest value from a dict and you don't care about what key it's associated with, you can just do:

max_value = max(d.values())

For the key of the max value:

max_key = max(d, key=d.get)

If you want both in a pair:

max_tuple = max(d.items(), key=lambda k: k[1])
Source Link
Sentox
  • 950
  • 1
  • 6
  • 4

If you just want the highest value from a dict and you don't care about what key it's associated with, you can just do:

max_value = max(d.values())