phyton dict

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

Write a Python program to find the highest 3 values in a dictionary.

in progress 0
Python 2 months 1 Answer 191 views 0

Answer ( 1 )

  1. rg123

    Please briefly explain why you feel this answer should be reported .

    Report
    Cancel
    from heapq import nlargest
    my_dict = {'a':500, 'b':5874, 'c': 560,'d':400, 'e':5874, 'f': 20}  
    three_largest = nlargest(3, my_dict, key=my_dict.get)
    print(three_largest)
    

    Output:
    [‘e’, ‘d’, ‘b’]
    Reference: http://www.w3resource.com/python-exercises/dictionary/python-data-type-dictionary-exercise-22.php

Leave an answer

Browse

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>