ProgrammingVery hardCodeforces-style · placement coding round
What is printed?
What is printed?
print(''.join(sorted('hello', key=lambda c: c in 'aeiou')))- A. ehllo
- B. hlloe
- C. hlleo
- 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
- What is printed? python print(len({(1, 2): 'a', (2, 1): 'b', (1, 2): 'c'}))
- What is printed? python x = 5 def f(): return x x = 6 print(f(), (lambda: x)())
- What is printed? python print(list(range(10))[2:8:3], list(range(10))[::4])
- What is printed? python print(not [] is [], (not []) is [])
- What is printed? python print(sum(map(int, '1234')), '1234'[::-1] == '4321')
- What is printed? python import heapq pts = [(1, 3), (-2, 2), (2, -2), (0, 1)] print(heapq.nsmallest(2, pts, key=lambda p: p[0] 2 + p[1] 2))