ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(sorted(['b', 'A', 'a', 'B']), sorted(['b', 'A', 'a', 'B'], key=str.lower))
- A. ['A', 'B', 'a', 'b'] ['A', 'B', 'a', 'b']
- B. ['A', 'B', 'a', 'b'] ['A', 'a', 'b', 'B']
- C. ['a', 'A', 'b', 'B'] ['A', 'a', 'b', 'B']
- D. ['A', 'B', 'a', 'b'] ['b', 'B', 'a', 'A']
Correct answer: B. ['A', 'B', 'a', 'b'] ['A', 'a', 'b', 'B']
A plain sort compares code points, so uppercase letters come first. With key=str.lower, equal keys keep their input order, so A comes before a and b before B.
More Python Programming questions
- What is printed? python print('a-b-c-d'.rsplit('-', 2), 'a-b-c-d'.split('-', 1))
- What is printed? python print('²'.isdigit(), '²'.isdecimal(), '٣'.isdecimal())
- What is printed? python m = ['abc', 'def'] print([''.join(t) for t in zip(m)])
- What is printed? python print(list(zip([[1, 2, 3], [4, 5]])), list(zip([[1, 2], [3, 4, 5]], strict=False)))
- What is printed? python from collections import deque a = [1, 3, -1, -3, 5, 3, 6, 7] k = 3 dq = deque() out = [] for i, x in enumerate(a)…
- What is printed? python import heapq class T: def init(self, p, n): self.p = p self.n = n def lt(self, o): return self.p > o.p h = [] for…