ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

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

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

Correct answer: D. [1, 3, 4, 5, 7, 9, 12] 3

^ 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, 4, 5, 7, 9, 12] 3.

More Python Programming questions

Exams that ask this topic