ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? a, b = set([12,12,1,7,1]), set([12,12,3,10,6,10]) print(sorted(a ^ b), len(a - b))

  1. A. [12] 2
  2. B. [1, 7] 5
  3. C. [1, 3, 6, 7, 10] 3
  4. D. [1, 3, 6, 7, 10] 2

Correct answer: D. [1, 3, 6, 7, 10] 2

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

More Python Programming questions

Exams that ask this topic