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}
>>>
Your answer is wrong
ReplyDeleteWhy, Solution is right , if you have doubt then you can copy it and run it in your python.
Deletewhat is the problem?
ReplyDeleteIn which questions.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )