ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from collections import Counter
print(Counter('abracadabra').most_common(3))- A. [('a', 5), ('b', 2), ('r', 2)]
- B. [('a', 5), ('r', 2), ('b', 2)]
- C. [('a', 5), ('b', 2), ('c', 1)]
- D. [('a', 5), ('r', 2), ('c', 1)]
Correct answer: A. [('a', 5), ('b', 2), ('r', 2)]
most_common sorts by count and keeps insertion order for ties. In 'abracadabra', b is first seen before r, so the two-count ties appear as b then r.
More Python Programming questions
- What is printed? python print(float(10 16 + 1) == 10 16, 10 16 + 1 == float(10 16 + 1))
- What is printed? python x = 0 def f(): global x x += 1 return x print(f() + f() 10, x)
- What is printed? python print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 3 0.1 == 0.3 - 0.2 + 0.1)
- What is printed? python nums = [3, 1, 2] nums2 = sorted(nums, reverse=True) nums.sort() print(nums, nums2, nums is sorted(nums))
- What is printed? python nums = [13, 22, 5, 31, 8, 3] print(sorted(nums, key=lambda x: x % 10), sorted(nums, key=lambda x: x % 10…
- What is printed? python def gen(): yield 1 return 5 yield 2 it = gen() print(list(it), next(it, 'done'))