ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(max('abc', 'abd', key=lambda s: s[::-1]), min('ba', 'ab', key=len))
  1. A. abd ba
  2. B. abc ab
  3. C. abd ab
  4. D. abc ba

Correct answer: A. abd ba

Reversed, 'abc' becomes 'cba' and 'abd' becomes 'dba', so the larger key is 'dba' and max returns 'abd'. min by length ties on both words, and min keeps the first, which is 'ba'.

More Python Programming questions

Exams that ask this topic