ProgrammingModerateAccenture · Capgemini pattern
What is printed?
What is printed?
d = dict(zip("abc", range(3)))
d.update({"b": 9, "d": 1})
print(list(d.items())[1], sum(d.values()), len(d))- A. ('b', 1) 12 4
- B. ('d', 1) 12 4
- C. ('b', 9) 13 4
- D. ('b', 9) 12 4
Correct answer: D. ('b', 9) 12 4
zip pairs a-0, b-1, c-2. update overwrites the value of the existing key b in place (b keeps its position) and appends the new key d. Items are a:0, b:9, c:2, d:1, so index 1 is ('b', 9), the values sum to 12 and there are 4 keys.
More Python Programming questions
- What is printed? python a = {1, 2, 3, 4} b = {3, 4, 5} print(a - b, b - a, len(a | b), a & b == {4, 3})
- What is printed? python print(" ".join(i ch for i, ch in enumerate("xyz", 1)), list(enumerate("ab"))[-1])
- What is printed? python nums = list(range(10)) print(nums[8:2:-2], nums[-3:], nums[2:8:-1])
- What is printed? python print(min([3, -4, 2], key=lambda v: v v), max({"a": 3, "b": 1}), max("abc", "b", key=len))
- What is printed? python class Box: def len(self): return 0 b = Box() print(bool(b), "yes" if b else "no", len([b, b]))
- What is printed? python a = [3, 1, 4, 1, 5] a.insert(-1, 9) print(a, a.index(1), a.pop(), a.count(1))