ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
d = {'a': 1, 'b': 2}
d['a'] = 3
d.pop('a')
d['a'] = 4
print(list(d.items()))- A. [('a', 4), ('b', 2)]
- B. [('a', 3), ('b', 2)]
- C. [('b', 2)]
- D. [('b', 2), ('a', 4)]
Correct answer: D. [('b', 2), ('a', 4)]
Updating an existing key keeps its position, but deleting and reinserting a key moves it to the end. Here 'a' is removed and added again after 'b'.
More Python Programming questions
- What is printed? python print({k % 4: k k for k in range(9, -1, -1)})
- What is printed? python print(sum([0.1] 10) == 1.0, 0.1 3 == 0.3)
- What is printed? python import heapq iv = sorted([(0, 30), (5, 10), (15, 20)]) h = [] for s, e in iv: if h and h[0] <= s…
- What is printed? python from collections import Counter a = [1, -1, 2, -2, 0] cnt = Counter({0: 1}) s = 0 ans = 0 for x in a: s += x ans…
- What is printed? python print(4 & 3 == 0, 6 & 3 == 0)
- What is printed? python print(int(1e23), int(1e20))