ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: C. eohll

The key is False for vowels and True for consonants, so vowels sort first. Within each group the letters are in alphabetical order, giving e and o, then h, l, l.

More Python Programming questions

Exams that ask this topic