python print 2nd highest value in dictionary

 


x = {
'Harry': 37.21,
'Berry': 37.21,
'Tina': 37.2,
'Akriti': 41.0,
'Harsh': 39.0
}

list = []

for i,k in x.items():

list.append(k)

# value converted to list
# print(list)

# 2nd highest value
secondHeighest = sorted(list)[1]

#sorted list
# print(secondHeighest)

# now match the value with key and print
for i,k in x.items():
if k == secondHeighest:
print(i)


Post a Comment

0 Comments