-3

I am trying to merge dictionaries returning from for loop. I have to then take maximum total from the dictionary. I am new to python. Please find below my code.

def winner(dictn):
for k,v in dictn.items():
    total = 0
    for k1,v1 in v.items():
        total = total+v1
        team = {k:total}
    print(team)
winner(qualifier_2)

And my current output is:

{'KKR': 2236}
{'MI': 1759}

dictionary after update should look like: {'KKR': 2236, 'MI':1759}

Then it should return the team which scored maximum runs ie. winner Expected output: KKR

1 Answers1

-1

if the dictonary is:

{
  "KKR": 1
  "MI" : 2 
}

you can run this code:

def winner(dictn):
    print(max(dictn, key=dictn.get))
  • Thanks for your reply. But the output from my code does not return as a single dictionary. Please find below my output. Actual output: {'KKR': 2226} {'MI': 1753} Expected output: {'KKR' : 2226, 'MI', 1753 } – Guru Prasath Jun 22 '18 at 08:23
  • @Joaquim De la Cruz you are giving a reverse answer. He wants the dictionary you are placing. – Elias Prado Nov 08 '21 at 14:40