-2

I have the following data structure, where my dictionary keys are a tuple. I want to extract the maximum of those key tuples based on it's second element.

dict_ = {(3,2):0.5,
        (1,5): 0.7}

I tried max(dict_.keys()) which returned (3,2).

My expected output is (1, 5), which is maximum of 2 and 5, the second elements of the tuple keys. Any help would be appreciated.

Slayer
  • 832
  • 1
  • 6
  • 21
J_yang
  • 2,672
  • 8
  • 32
  • 61

1 Answers1

0

You can use max() with key parameter:

max(dictp, key=lambda x: x[1])
# (1, 5)
Austin
  • 25,759
  • 4
  • 25
  • 48