ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(''.join(sorted(set('mississippi'))), ''.join(sorted('mississippi', key=lambda c: (-'mississippi'.count(c), c)))[:3])
  1. A. imps imm
  2. B. imps iis
  3. C. imps iii
  4. D. mips iii

Correct answer: C. imps iii

set removes duplicates, and sorting the four distinct letters gives imps. Sorting by descending count puts the four i's first, followed by the four s's.

More Python Programming questions

Exams that ask this topic