ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
words = ['apple', 'Bob', 'cat']
print(sorted(words, key=str.casefold)[0], sorted(words)[0], max(words, key=len))
  1. A. Bob Bob apple
  2. B. apple apple apple
  3. C. apple Bob apple
  4. D. apple Bob cat

Correct answer: C. apple Bob apple

casefold makes 'apple' the smallest word, while plain sorting puts uppercase 'Bob' first. max by length picks 'apple', the first of the longest words, since max keeps the first maximum it meets.

More Python Programming questions

Exams that ask this topic