ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
s = {3, 1, 2}
t = frozenset([1, 2])
print(t < s, s > t, s.isdisjoint({4}), {t: "ok"}[frozenset({2, 1})])- A. False True True ok
- B. True True True ok
- C. True True False ok
- D. True True True KeyError
Correct answer: B. True True True ok
< and > on sets test proper subset/superset. frozensets are hashable and equal regardless of construction order, so a frozenset with the same elements finds the key.
More Python Programming questions
- What is printed? python a = [3, 1, 2] b = a.sort() or a c = sorted(a, reverse=True) a.reverse() print(b, c, b is a)
- What is printed? python data = [("b", 2), ("a", 2), ("c", 1), ("a", 1)] print(sorted(data, key=lambda t: t[1]), sorted(data)[0])
- What is printed? python def f(a, /, b, , c): return a + b + c for call in ["f(1, 2, c=3)", "f(1, b=2, c=3)", "f(a=1, b=2, c=3)", "f(1, 2…
- What is printed? python def f(a, kw): return a, kw print(f(1, {"b": 2}), f({"a": 3, "kw": 4}), end=" ") try: f(1, {"a": 2}) except…
- What is printed? python def f(x, , y=2, kw): return x y + len(kw) opts = {"y": 3, "z": 0} print(f(2, opts), f(2, z=1, w=1))
- What is printed? python log = [] def v(x): log.append(x) return x def f(a, k): return a, k f(v(1), [v(2)], k=v(3), {"m": v(4)}) print(log)