ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
words = ["kiwi", "fig", "apple", "date"]
print(sorted(words, key=len), max(words, key=len), min(words))
  1. A. ['fig', 'kiwi', 'date', 'apple'] apple apple
  2. B. ['fig', 'date', 'kiwi', 'apple'] apple apple
  3. C. ['fig', 'kiwi', 'date', 'apple'] apple fig
  4. D. ['apple', 'date', 'fig', 'kiwi'] apple apple

Correct answer: A. ['fig', 'kiwi', 'date', 'apple'] apple apple

A stable sort by length keeps 'kiwi' before 'date' (both length 4) in their original order. min without a key compares alphabetically, so 'apple' is smallest.

More Python Programming questions

Exams that ask this topic