ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
from collections import Counter
a = Counter("aabbbc")
b = Counter("abccd")
print(sorted((a - b).items()), sorted((a & b).items()), (a + b)["c"])
  1. A. [('a', 1), ('b', 2), ('c', -1), ('d', -1)] [('a', 1), ('b', 1), ('c', 1)] 3
  2. B. [('a', 1), ('b', 2)] [('a', 1), ('b', 1), ('c', 1)] 3
  3. C. [('a', 1), ('b', 2)] [('a', 2), ('b', 3), ('c', 2), ('d', 1)] 3
  4. D. [('a', 1), ('b', 2), ('c', 0)] [('a', 1), ('b', 1), ('c', 1)] 3

Correct answer: B. [('a', 1), ('b', 2)] [('a', 1), ('b', 1), ('c', 1)] 3

Counter subtraction keeps only positive counts (c would be -1, d -1, both dropped). & takes the minimum count per key (keys absent in one side give 0 and vanish). + adds: c = 1 + 2 = 3.

More Python Programming questions

Exams that ask this topic