CBSE Class 11 Computer Science Question 44 of 112

Dictionaries — Question 24

Back to all questions
24
Question

Question 24

Running the code sorted(my_dictionary, reverse = True) on a dictionary named my_dictionary will return results sorted in what order?

  1. Ascending order (A-Z), by key
  2. Ascending order (A-Z), by value
  3. Descending order (Z-A), by key
  4. Descending order (Z-A), by value
Answer

Descending order (Z-A), by key

Reason — The sorted() function returns a sorted list of dictionary keys. By default, the sort order is ascending. To sort the keys in descending order, the reverse parameter must be set to true as an optional argument (sorted(my_dictionary, reverse = True)).