ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(''.join(sorted('hello', key=lambda c: (c not in 'aeiou', c))))- A. ehllo
- B. eolhl
- C. eohll
- 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
- What is printed? python print(round(0.1 0.1, 3) == 0.01, round(2.345, 2), round(2.355, 2))
- What is printed? python print(max(1, 2.0, True), min([0.0, -0.0, 0]), sum([]) == 0.0)
- What is printed? python print(10100 // 1098, (10100) % 97 == pow(10, 100, 97))
- What is printed? python print(sorted(['b10', 'b9', 'a10'], key=lambda s: (s[0], int(s[1:]))))
- What is printed? python print(sorted('bAcB', key=str.upper), sorted('bAcB'))
- What is printed? python print(int('0' + '9' 3) + 1, int('9' 3 + '0') + 1)