ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? a, b = set([2,10,5,12,11,10]), set([12,5,9,3]) print(sorted(a ^ b), len(a - b))

  1. A. [2, 3, 9, 10, 11] 2
  2. B. [2, 3, 9, 10, 11] 3
  3. C. [5, 12] 3
  4. D. [2, 3, 5, 9, 10, 11, 12] 3

Correct answer: B. [2, 3, 9, 10, 11] 3

^ keeps elements in exactly one set (symmetric difference); a − b keeps those only in a. Duplicates collapse when the sets are built. Output: [2, 3, 9, 10, 11] 3.

More Python Programming questions

Exams that ask this topic