ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
from collections import OrderedDict
a = {"x": 1, "y": 2}
b = {"y": 2, "x": 1}
c = OrderedDict(a)
e = OrderedDict(b)
print(a == b, c == e, c == b, a.keys() & b.keys() == {"x", "y"})
  1. A. True True True True
  2. B. False False True True
  3. C. True False False True
  4. D. True False True True

Correct answer: D. True False True True

Plain dict equality ignores order. Two OrderedDicts compare order-sensitively, so c != e. OrderedDict vs plain dict ignores order. Key views support set operations, and & returns a plain set equal to {'x', 'y'}.

More Python Programming questions

Exams that ask this topic