1. Home
  2. Data Science
  3. Python
  4. What is the output of print(sorted(['banana', 'pie'…

Added 25 Nov 2026

What is the output of print(sorted(['banana', 'pie', 'apple'], key=len)) in Python?

print(sorted(['banana', 'pie', 'apple'], key=len))
  1. ['apple', 'banana', 'pie']
  2. ['banana', 'apple', 'pie']
  3. ['pie', 'apple', 'banana'] Correct answer
  4. ['pie', 'banana', 'apple']

Correct answer

C. ['pie', 'apple', 'banana']

6 views

MCQSEXAM

Explanation

key=len sorts by string length: pie (3), apple (5), banana (6).

Reference

Asked in: Python Interview Lists

https://docs.python.org/3/tutorial/datastructures.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs