Computer Science
Running the code sorted(mydictionary, reverse = True) on a dictionary named mydictionary will return results sorted in what order?
- Ascending order (A-Z), by key
- Ascending order (A-Z), by value
- Descending order (Z-A), by key
- Descending order (Z-A), by value
Python Dictionaries
1 Like
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)).
Answered By
1 Like
Related Questions
Which of the following Python codes will give the same output if
dict = {"diary":1, "book":3, "novel":5}(i) dict.pop("book")
(ii) del dict["book"]
(iii) dict.update({"diary":1,"novel":5})- (i), (ii), (iii)
- (1), (ii)
- (i), (iii)
- (ii), (iii)
What will be the output of following Python code?
d1 = {"a":10,"b":2,"c":3} str1="" for i in d1: str1 = str1 + str(d1[i]) + " " str2 = str1[:-1] print(str2[::-1])- 3, 2
- 3, 2, 10
- 3, 2, 01
- Error
Fill in the blanks:
The keys of a dictionary must be of _________ types.
Fill in the blanks:
The order of a dictionary's elements is _________.