ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
d = {"a": 1, "b": 2, "c": 3}
del d["a"]
d["a"] = 4
d.pop("b")
d["b"] = 5
print(list(d.items()), next(iter(d)), next(reversed(d)))- A. [('c', 3), ('a', 4), ('b', 5)] c b
- B. [('a', 4), ('b', 5), ('c', 3)] a c
- C. [('c', 3), ('a', 4), ('b', 5)] c c
- D. [('a', 4), ('c', 3), ('b', 5)] a b
Correct answer: A. [('c', 3), ('a', 4), ('b', 5)] c b
Deleting a key and inserting it again puts it at the end of the insertion order. Since Python 3.8, dicts and their views support reversed().
More Python Programming questions
- What is printed? python class Key: def init(self, v): self.v = v def hash(self): return hash(self.v) def eq(self, o): return self.v == o.v…
- What is printed? python d = dict.fromkeys(range(3), 0) for k in d: d[k] += k e = {k: [] for k in "ab"} e["a"].append(1) f =…
- What is printed? python x = None print(x is None, x == None, bool(None), type(None).name, None is not False)
- What is printed? python class P: pass p = P() p.n = 1 p.n += 1 P.m = 10 q = P() q.m += 5 print(p.n, P.m, q.m, p.m, vars(q))
- What is printed? python def makeacc(): total = [] def add(x): total.append(x) return sum(total) def reset(): nonlocal total total = []…
- What is printed? python adders = [lambda x, n=n: x + n for n in range(3)] mults = list(map(lambda n: (lambda x: x n), range(3)))…