ProgrammingVery hardCAT · MBA placement

What is printed?

What is printed?
from collections import Counter
a = Counter('aabbbc')
b = Counter('abbd')
print(a - b, (a + b)['b'], sorted((a & b).items()))
  1. A. Counter({'b': 1, 'a': 1, 'c': 1}) 5 [('a', 1), ('b', 2)]
  2. B. Counter({'a': 1, 'b': 1, 'c': 1}) 4 [('a', 1), ('b', 2)]
  3. C. Counter({'a': 1, 'b': 1, 'c': 1}) 5 [('a', 1), ('b', 2)]
  4. D. Counter({'a': 1, 'b': 1, 'c': 1}) 5 [('a', 1), ('b', 1)]

Correct answer: C. Counter({'a': 1, 'b': 1, 'c': 1}) 5 [('a', 1), ('b', 2)]

Subtraction keeps only positive counts and follows the first counter's key order. a + b gives 3 + 2 = 5 for b, and & takes the minimum of each count.

More Python Programming questions

Exams that ask this topic