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))- A. 3 [1, 2]
- B. 2 [1, 2, 3]
- C. 3 [1, 2, 3]
- 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
- What is printed? python print(frozenset([1, 2]) == {1, 2}, {frozenset([1]): 'x'}[frozenset([1])])
- What is printed? python a = [1, 2, 3] r = a.reverse() print(r, a)
- What is printed? python t = (1) u = (1,) print(type(t).name, type(u).name, len(u))
- What is printed? python try: print(1.0 // 0.0) except ZeroDivisionError as e: print(e)
- What is printed? python print(int('0x1A', 16), int('1A', 16), int('0x1A', 0))
- What is printed? python print(len(str(10 400 // 3)))