ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(max('bca'), min('bca', key=lambda c: (c, -ord(c))))
  1. A. c a
  2. B. c c
  3. C. b a
  4. D. a c

Correct answer: A. c a

max of the characters is 'c'. The key (c, -ord(c)) is the character itself, so min is 'a'. The second element of the key only breaks ties, and there are none here.

More Python Programming questions

Exams that ask this topic