Q. Election is a dictionary where key, value pair are in the form of name : votes received.

Write a program that sorts the contents of the election dictionary and create two list that stores the sorted data. list a [i] will contain the name of the candidate and list b [i] will contain the votes received by candidate list a[i]. print the name of candidates with votes received in decreasing order of the number of votes received.


You can understand by Watching video :-



Answer :-

election = {"portal":99,"express":40,"path":50,"walla":90,"computer":60,"python":49}
b = list(election.values())
a = list(election.keys())
b.sort()
dic = {}

for i in range(len(b)):
    for j in a :
        if b [ i ] == election [ j ] :
            dic [ j ] = b [ i ]
print(dic)


Output:-

{'express': 40, 'python': 49, 'path': 50, 'computer': 60, 'walla': 90, 'portal': 99}
>>>

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post