ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
d = {0: "zero", False: "F", 0.0: "f", "": "e"}
s = {1, True, 1.0, -0.0, 0}
print(d, len(s))- A. {0: 'zero', False: 'F', 0.0: 'f', '': 'e'} 5
- B. {0: 'f', '': 'e'} 2
- C. {False: 'f', '': 'e'} 2
- D. {0: 'zero', '': 'e'} 2
Correct answer: B. {0: 'f', '': 'e'} 2
0, False and 0.0 are equal and hash the same, so they are one key: the FIRST key object (0) is kept and the LAST value ('f') wins. In the set, 1/True/1.0 collapse to one item and -0.0/0 to another.
More Python Programming questions
- What is printed? python nan = float("nan") L = [nan] print(nan == nan, nan in L, L == [nan], [float("nan")] == [float("nan")])
- What is printed? python from collections import OrderedDict a = {"x": 1, "y": 2} b = {"y": 2, "x": 1} c = OrderedDict(a) e =…
- What is printed? python from collections import defaultdict d = defaultdict(list) d["a"].append(1) = d["b"] print("c" in d, d.get("c")…
- What is printed? python from collections import Counter a = Counter("aabbbc") b = Counter("abccd") print(sorted((a - b).items())…
- What is printed? python a = {"x": 1, "y": 2} b = {"y": 3, "z": 4} c = a | b a |= {"w": 0} print(c, b | a)
- What is printed? python d = {i: i i for i in range(4)} try: for k in d: if k == 1: del d[k] except RuntimeError: print("RE", end=" ") for…