ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
a = [3, 1, 2] b = sorted(a, key=lambda x: -x) a.sort(reverse=True) print(a == b, a, b)
- A. False [3, 2, 1] [3, 2, 1]
- B. True [1, 2, 3] [3, 2, 1]
- C. True [3, 2, 1] [3, 2, 1]
- D. True [3, 1, 2] [3, 2, 1]
Correct answer: C. True [3, 2, 1] [3, 2, 1]
sorted returns a new list and sort() sorts in place, but both use a descending order here, so the contents match. The printed values are the final states of a and b.
More Python Programming questions
- What is printed? python print(pow(7, 222, 10), pow(7, 222, 1000), 7222 % 1000, pow(-7, 3, -5))
- What is printed? python print(int(True) + int('0b11', 2), int(3.7 // 1), int(-0.5), round(-0.5), round(0.5))
- What is printed? python n = 0b10110000 print(n & -n, n & (n - 1), bin(n >> 4), n.bitcount())
- What is printed? python a, b = 5, 9 a ^= b b ^= a a ^= b print(a, b, a ^ b)
- What is printed? python print(0xFF >> 4 << 4 == 0xF0, 1 << 63 > 0, (1 << 63) - 1 == 263 - 1, -(1 << 63) >> 63)
- What is printed on the third line? python names = ['bob', 'Alice', 'carl', 'Bob', 'alice'] print(sorted(names)) print(sorted(names…