ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(sorted(['b', 'B', 'a'], key=lambda s: (s.lower(), s)))
- A. ['a', 'B', 'b']
- B. ['c', 'B', 'b']
- C. ['B', 'a', 'b']
- D. ['b', 'a', 'd']
Correct answer: A. ['a', 'B', 'b']
The key is a tuple of the lowercase letter and the original string. a comes first, and within the b group, uppercase B has the smaller code point, so B comes before b.
More Python Programming questions
- What is printed? python from math import prod print(prod([2, 3, 4]), prod([]), prod([0.5, 4]), prod(range(1, 4), start=10))
- What is printed? python print(2 -1 2 1, 2 -(1 2) 1, (2 -1) (2 1))
- What is printed? python print('%-5s|%5s|' % ('ab', 'cd'), '%(x)d-%(y)s' % {'x': 1, 'y': 'z'})
- What is printed? python print(0.1 3 == 0.30000000000000004, 0.1 3 - 0.3 == 5.551115123125783e-17, 0.3 - 0.1 3 == -5.551115123125783e-17)
- What is printed? python print(len('ab' + 'c' 0), 'ab'[1:][0] 2, ('ab' 2)[::3])
- What is printed? python print(int(' 3 ') + 1, int('3n') 2, float(' 2.5t') 2)