1

Let's say that I have a dictionary as follow:

dictionary = {"A": "9",  "B": "8",  "C": 10}

I want to print the keys only for the dictionary but sorted according to the value of the key. For example, I want it to be sorted according to the biggest value to the smallest value (on the same line).

So the output of this should be

C A B

How can I do this?

Jan
  • 747
  • 1
  • 10
  • 29

1 Answers1

2

Use sorted:

print(' '.join(sorted(dictionary.keys(),key=lambda x: -dictionary[x])))

Output:

C A B
U13-Forward
  • 69,221
  • 14
  • 89
  • 114