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
  • 746
  • 1
  • 8
  • 28

1 Answers1

1

Use sorted:

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

Output:

C A B
U12-Forward
  • 65,118
  • 12
  • 70
  • 89