ProgrammingVery hardCodeforces-style · placement coding round

What is printed?

What is printed?
print(''.join(sorted('hello', key=lambda c: c in 'aeiou')))
  1. A. ehllo
  2. B. hlloe
  3. C. hlleo
  4. D. lhleo

Correct answer: C. hlleo

The key is False for consonants and True for vowels, and sorted is stable. So the consonants h, l, l come first in their original order, followed by the vowels e and o.

More Python Programming questions

Exams that ask this topic