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))
  1. A. ('b', 1) 12 4
  2. B. ('d', 1) 12 4
  3. C. ('b', 9) 13 4
  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

Exams that ask this topic