ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sorted(['b', 'A', 'a', 'B'], key=str.lower))
- A. ['b', 'B', 'A', 'a']
- B. ['A', 'a', 'b', 'B']
- C. ['A', 'B', 'a', 'b']
- D. ['b', 'a', 'A', 'B']
Correct answer: B. ['A', 'a', 'b', 'B']
The keys are 'a', 'a', 'b', 'b'. Timsort is stable, so among equal keys the original order holds: A before a (positions 1 and 2) and b before B (positions 0 and 3).
More Python Programming questions
- What is printed? python nums = map(int, '1 2 3'.split()) a = list(nums) b = list(nums) print(a, b)
- What is printed? python print(1020 + 1 - 1020, float(1020 + 1) - float(1020))
- What is printed? python data = [('b', 2), ('a', 2), ('c', 1), ('a', 1)] print(sorted(sorted(data, key=lambda t: t[0]), key=lambda t: t[1]…
- What is printed? python print(int('0x1F', 16), int('1F', 16), int('0b101', 0), int(' 42 '), int('42'))
- What is printed? python print(int('٣') + 1)
- What is printed? python print(bin(10)[2:].zfill(8), format(-10, '08b'), format(-10 & 0xFF, '08b'), f'{255:#x}')