ProgrammingModerateCognizant GenC · TCS NQT
What is printed?
What is printed?
d = {'a': 1, 'b': 2, 'c': 3}
d['a'] = 9
del d['b']
d['b'] = 5
print(list(d.items()))- A. [('a', 9), ('b', 5), ('c', 3)]
- B. [('b', 5), ('a', 9), ('c', 3)]
- C. [('a', 9), ('c', 3), ('b', 5)]
- D. [('a', 1), ('c', 3), ('b', 5)]
Correct answer: C. [('a', 9), ('c', 3), ('b', 5)]
Updating an existing key keeps its position, deleting b removes it, and reinserting b puts it at the end. The insertion order is then a, c, b.
More Python Programming questions
- What is printed? python import bisect a = [(1, 'x'), (3, 'y'), (3, 'z'), (7, 'w')] i = bisect.bisectleft(a, 3, key=lambda p: p[0]) j =…
- Which statement about counting pairs i < j with a[i] + a[j] == t is FALSE?
- What is printed? python a = [] for i in range(20): a.append(i) print(len(a), a[-1], a.pop(), len(a))
- What is printed? python print(int('0012'), int('ff', 16), int('0b11', 0), int('1234'))
- What is printed? python print(-7 // 2, -7 % 2, 7 // -2, 7 % -2, divmod(-7, 2))
- What is printed? python print(round(0.5), round(1.5), round(2.5), round(-0.5), round(2.675, 2))