ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
from collections import Counter
c = Counter('mississippi')
print(c.most_common(2))- A. [('i', 4), ('s', 4)]
- B. [('s', 4), ('i', 4)]
- C. [('i', 4), ('p', 2)]
- D. [('i', 4), ('m', 1)]
Correct answer: A. [('i', 4), ('s', 4)]
Counter keeps first-seen order for ties, and i appears before s in mississippi, so most_common(2) lists i first.
More Python Programming questions
- What is printed? python def maxprod(a): best = curmax = curmin = a[0] for x in a[1:]: cands = (x, curmax x, curmin x) curmax, curmin =…
- What is printed? python def jumps(a): j = cur = far = 0 for i in range(len(a) - 1): far = max(far, i + a[i]) if i == cur: j += 1 cur = far…
- What is printed? python def profit(p): lo, best = float('inf'), 0 for x in p: lo = min(lo, x) best = max(best, x - lo) return best…
- What is the time complexity of building a binary heap from n unordered items with heapq.heapify?
- Which statement about bisect.insort(a, x) on a plain Python list a is true?
- What is printed? python import itertools print(list(itertools.accumulate([3, 1, 4], initial=10)))