ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(sorted(['b', 'a', 'c'], key=lambda s: -ord(s)))
- A. ['c', 'b', 'a']
- B. ['a', 'b', 'c']
- C. ['b', 'a', 'c']
- D. ['c', 'a', 'b']
Correct answer: A. ['c', 'b', 'a']
The key negates the code point, so larger letters have smaller keys and come first. This sorts the letters in reverse alphabetical order.
More Python Programming questions
- What is printed? python print(sorted([0.5, -0.5, 0, True, False], key=abs))
- What is printed? python print(str(2100)[:5], len(str(2100)), str(2100).count('0'))
- What is printed? python print(int('9' 5) 2 // 109, (109 - 1) 2 // 109)
- What is printed? python x = 0 for i in range(1, 101): x += i print(x, x // 2 2 == x, x % 2)
- What is printed? python print(','.join(['a', 'b']), ','.join('ab'), '%s' % ['a', 'b'], str(('a',)))
- What is printed? python import math print(math.prod([2, 3, 4]), math.prod([]), math.prod([1.5, 2]), math.prod(range(1, 6)) ==…