ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from collections import Counter
d = {'a': 1, 'b': 2}
v = d.values()
d['c'] = 3
print(len(v), list(v))
  1. A. 3 [1, 2]
  2. B. 2 [1, 2, 3]
  3. C. 3 [1, 2, 3]
  4. D. 2 [1, 2]

Correct answer: C. 3 [1, 2, 3]

dict views are live. The values view reads the dictionary when used, so it shows the new key's value too.

More Python Programming questions

Exams that ask this topic