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})])
  1. A. False True True ok
  2. B. True True True ok
  3. C. True True False ok
  4. 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

Exams that ask this topic