What is the output of print(sorted(['banana', 'pie', 'apple'], key=len)) in Python?
print(sorted(['banana', 'pie', 'apple'], key=len))
Correct answer
C. ['pie', 'apple', 'banana']
8 views
C. ['pie', 'apple', 'banana']
8 views
key=len sorts by string length: pie (3), apple (5), banana (6).
Asked in: Python Interview Lists
https://docs.python.org/3/tutorial/datastructures.htmlNot sure why the answer is C? Ask here and get an explanation.