-2

Here is the dictionary:

{'A': [2, 4.2], 
 'B': [4, 4.5],
 'C': [2, 3.3], 
 'D': [2, 3.5], }

Sorting criteria:

  1. Sort based on the 1st(first) element of list of VALUE.

  2. If the 1st element is the same for two keys, the one with the greater value of 2nd element is chosen as the greater one.

The result should be:

B -- 4 -- 4.50

A -- 2 -- 4.20

D -- 2 -- 3.50

C -- 2 -- 3.30

1 Answers1

0

You may sort the dictionary using various methods but if your goal is to print it, you simply cannot because Dictionaries are unpredictable and the output is random, you might want to use Ordered Dictionaries and / or use the sort function to sort them.

So that we can help you better, please show us what you tried and the errors you face so that it’s easier for us to help you out.

Rajat Shenoi
  • 590
  • 2
  • 7
  • 22
  • Dictionaries are not unpredictable - they are insert ordered. The order you insert keys rules how they are outputted - this holds for any python 3.7+, some pythons 3.6+ due to implementation details. – Patrick Artner Feb 09 '21 at 17:08