To reverse a dictionary and display values

Heisenberg

I want to reverse a dictionary and display it in a specific format. Here is the sample input:

{'john':34.480, 'eva':88.5, 'alex':90.55, 'tim': 65.900} 

Output should be:

enter image description here

This is where I am with the code, but the problem is that it returns a list and not a dictionary.

CODE:

def formatted_print(my_dict):
    d = my_dict
    c = sorted(d.items(), cmp=lambda a,b: cmp(a[1], b[1]), reverse=True)
    return (c)
ohid

Simple code without importing any module or library :

def formatted_print(D):
    list_tuples=sorted(D.items(), key=lambda x: (-x[1], x[0]))

    for items in list_tuples:
        x="{0:10s}{1:6.2f}".format(items[0],items[1])
        print(x)

It prints:

alex       90.55
eva        88.50
tim        65.90
john       34.48

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Reverse keys and values in dictionary

From Dev

Reverse keys and values in dictionary

From Dev

Reverse multiple values with keys in dictionary

From Dev

How to display values in a dictionary?

From Dev

How to reverse a dictionary (whose values are lists) in Python?

From Dev

How to display unicoded dictionary values

From Dev

How to Display selected values from a dictionary to a listbox

From Dev

How to reverse dictionary items and list keys grouped by common values

From Dev

Python : reverse keys and values in dictionary considering strings and not caracters

From Dev

Looping over a dictionary to display key and values in order of a value

From Dev

how to display dictionary keys as sections and values as rows in a table view in ios?

From Dev

How to display and remove values in dictionary which holds duplicate keys

From Java

Reverse / invert a dictionary mapping

From Dev

Reverse key and value in dictionary

From Dev

Reverse key and value in dictionary

From Dev

Reverse string translation with dictionary

From Dev

Reverse Dictionary function

From Dev

how to do a dictionary reverse lookup

From Dev

Reverse phonemes not included in the CMU dictionary

From Dev

How to reverse SeekBar values?

From Dev

perl: reverse values in a column

From Dev

How do I take a Python List of Dictionary Values and display in Kivy UI as a table (Using ListView Widget)?

From Dev

foreach Dictionary<>.Values or foreach Dictionary<>

From Dev

Grab Values Within a Dictionary in a Dictionary

From Dev

foreach Dictionary<>.Values or foreach Dictionary<>

From Dev

Ruby how to reverse display order

From Dev

Sorting a dictionary by REVERSE VALUE then NON-REVERSE KEY

From Dev

Sorting a dictionary by REVERSE VALUE then NON-REVERSE KEY

From Dev

Comparing a dictionary of values to a list of values

Related Related

  1. 1

    Reverse keys and values in dictionary

  2. 2

    Reverse keys and values in dictionary

  3. 3

    Reverse multiple values with keys in dictionary

  4. 4

    How to display values in a dictionary?

  5. 5

    How to reverse a dictionary (whose values are lists) in Python?

  6. 6

    How to display unicoded dictionary values

  7. 7

    How to Display selected values from a dictionary to a listbox

  8. 8

    How to reverse dictionary items and list keys grouped by common values

  9. 9

    Python : reverse keys and values in dictionary considering strings and not caracters

  10. 10

    Looping over a dictionary to display key and values in order of a value

  11. 11

    how to display dictionary keys as sections and values as rows in a table view in ios?

  12. 12

    How to display and remove values in dictionary which holds duplicate keys

  13. 13

    Reverse / invert a dictionary mapping

  14. 14

    Reverse key and value in dictionary

  15. 15

    Reverse key and value in dictionary

  16. 16

    Reverse string translation with dictionary

  17. 17

    Reverse Dictionary function

  18. 18

    how to do a dictionary reverse lookup

  19. 19

    Reverse phonemes not included in the CMU dictionary

  20. 20

    How to reverse SeekBar values?

  21. 21

    perl: reverse values in a column

  22. 22

    How do I take a Python List of Dictionary Values and display in Kivy UI as a table (Using ListView Widget)?

  23. 23

    foreach Dictionary<>.Values or foreach Dictionary<>

  24. 24

    Grab Values Within a Dictionary in a Dictionary

  25. 25

    foreach Dictionary<>.Values or foreach Dictionary<>

  26. 26

    Ruby how to reverse display order

  27. 27

    Sorting a dictionary by REVERSE VALUE then NON-REVERSE KEY

  28. 28

    Sorting a dictionary by REVERSE VALUE then NON-REVERSE KEY

  29. 29

    Comparing a dictionary of values to a list of values

HotTag

Archive