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()))- A. Counter({'b': 1, 'a': 1, 'c': 1}) 5 [('a', 1), ('b', 2)]
- B. Counter({'a': 1, 'b': 1, 'c': 1}) 4 [('a', 1), ('b', 2)]
- C. Counter({'a': 1, 'b': 1, 'c': 1}) 5 [('a', 1), ('b', 2)]
- 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
- What is printed? python print(pow(2, 100, 97), 2 100 % 97, (-2) 3 % 5, pow(-2, 3, 5))
- What is printed? python from itertools import permutations, combinations print(len(list(permutations('abcd', 2)))…
- What is printed? python def sqsorted(a): l, r = 0, len(a) - 1 out = [0] len(a) k = len(a) - 1 while l <= r: if abs(a[l]) > abs(a[r])…
- What is printed? python def minpath(g): dp = [0] len(g[0]) for i, row in enumerate(g): for j, v in enumerate(row): if i == 0 and j == 0…
- What is printed? python from functools import lrucache def wb(s, words): @lrucache(maxsize=None) def go(i): if i == len(s): return 1…
- What is printed? python from functools import cache @cache def ways(s, i=0): if i == len(s): return 1 if s[i] == '0': return 0 total =…