ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
d = {"a": 1, "b": 2, "c": 3}
d["a"] = 10
del d["b"]
d["b"] = 20
d.update({"a": 0, "z": 9})
print(list(d), d.popitem())- A. ['a', 'b', 'c', 'z'] ('z', 9)
- B. ['c', 'b', 'a', 'z'] ('z', 9)
- C. ['a', 'c', 'b', 'z'] ('z', 9)
- D. ['a', 'c', 'b', 'z'] ('a', 0)
Correct answer: C. ['a', 'c', 'b', 'z'] ('z', 9)
Updating an existing key keeps its original position; deleting and re-inserting moves a key to the end. popitem() removes the most recently inserted pair (LIFO), which is ('z', 9).
More Python Programming questions
- What is printed? python d = {0: "zero", False: "F", 0.0: "f", "": "e"} s = {1, True, 1.0, -0.0, 0} print(d, len(s))
- What is printed? python nan = float("nan") L = [nan] print(nan == nan, nan in L, L == [nan], [float("nan")] == [float("nan")])
- What is printed? python from collections import OrderedDict a = {"x": 1, "y": 2} b = {"y": 2, "x": 1} c = OrderedDict(a) e =…
- What is printed? python from collections import defaultdict d = defaultdict(list) d["a"].append(1) = d["b"] print("c" in d, d.get("c")…
- What is printed? python from collections import Counter a = Counter("aabbbc") b = Counter("abccd") print(sorted((a - b).items())…
- What is printed? python a = {"x": 1, "y": 2} b = {"y": 3, "z": 4} c = a | b a |= {"w": 0} print(c, b | a)