-1

the input I have given is

  • BatmanA,14
  • BatmanB,199
  • BatmanC,74
  • BatmanD,15
  • BatmanE,9

and the output i expect is the highest value and i get something else this is my code below i have tried other methods too pls help thanks.

N = int(input("Enter the number of batsman : "))

d = {}

for i in range(0,N):
    batsman = input("enter the batsman values " ).split(',')
    d[batsman[0]] = batsman[1]
v = list(d.values())
k = list(d.keys())
print(k[v.index(max(v))])
  • what result do you get? one issue is probably that the value is currently a string, so the `max` function does behave as you would expect if the values where numbers – njzk2 Jan 16 '20 at 08:09

1 Answers1

0
d[max(d, key=d.get)]

See Getting key with maximum value in dictionary? for more discussion.

Shashank V
  • 10,007
  • 2
  • 25
  • 41