ProgrammingVery hardPython · GATE DA · Advanced
What is printed?
What is printed?
d = {'a': 1, 'b': 2, 'c': 3}
del d['a']
d['a'] = 0
d |= {'b': 9, 'z': 4}
print(list(d.items()), min(d, key=d.get))- A. [('b', 9), ('c', 3), ('a', 0), ('z', 4)] a
- B. [('a', 0), ('b', 9), ('c', 3), ('z', 4)] a
- C. [('c', 3), ('a', 0), ('b', 9), ('z', 4)] a
- D. [('b', 9), ('c', 3), ('a', 0), ('z', 4)] c
Correct answer: A. [('b', 9), ('c', 3), ('a', 0), ('z', 4)] a
A deleted and re-added key goes to the end; |= updates existing b in place (keeping its position) and appends new z. min by value picks 'a' (0).
More Python Programming questions
- What is printed? python x = [1, 2, 3, 4, 5, 6] for i in x: if i % 2 == 0: x.remove(i) d = {'a': 1} try: for k in d: d[k + 'x'] = 0 except…
- What is printed? python words = ['bb', 'a', 'cc', 'd', 'aa'] print(sorted(words, key=len, reverse=True)) print(sorted(words, key=lambda w…
- What is printed? python a = list(range(6)) a[1:4] = 'xy' print(a) try: a[::2] = [0, 0] except ValueError as e: print('VE') a[2:2] = [7]…
- What is printed? python a = [1, 2, 3] b = a b += [4] c = a c = c + [5] print(a, c)
- What is printed? python d = {'a': 1, 'b': 2} d['c'] = 3 del d['a'] d['a'] = 9 print(list(d.items()))
- What is printed? python s = "a,b,,c" print(s.split(','), s.split(',', 1), " x y ".split())