ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
from collections import Counter
print(Counter('mississippi').most_common(3))- A. [('i', 4), ('s', 4), ('p', 2)]
- B. [('s', 4), ('i', 4), ('p', 2)]
- C. [('i', 4), ('s', 4), ('m', 1)]
- D. [('i', 4), ('p', 2), ('s', 4)]
Correct answer: A. [('i', 4), ('s', 4), ('p', 2)]
Counts are i=4, s=4, p=2 and m=1. most_common keeps tied items in the order they were first seen, so i (seen before s) comes before s, and the top three are i, s and p.
More Python Programming questions
- What is printed? python from functools import lrucache @lrucache(None) def total(xs): return sum(xs) try: print(total([1, 2, 3])) except…
- What is printed? python import bisect print(bisect.bisectleft(range(100), True, key=lambda x: x x >= 50))
- What is printed? python n = 30 s = [True] (n + 1) s[0] = s[1] = False for i in range(2, int(n 0.5) + 1): if s[i]: s[i i::i] = [False]…
- What is printed? python print(-0.0 == 0.0, str(-0.0), repr(0.0 -1))
- What is printed? python print(float('1000.5'), end=' ') try: int('10') except ValueError: print('VE')
- What is printed? python d = {1: 1} try: for k in d: d[k + 1] = 0 except RuntimeError as e: print(e)