Computer Science
If sorted( ) is applied on a dictionary, what does it return ?
Python Dictionaries
1 Like
Answer
If only sorted() is applied on dictionary then it considers only the keys of the dictionary for sorting and returns a sorted list of the dictionary keys.
For example:
d = {2 : "def" , 3 : "abc" , 1 : "mno"}
print(sorted(d))
Output
[1, 2, 3]
Answered By
2 Likes