ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
from collections import Counter
print(''.join(c * n for c, n in Counter('tree').most_common()))- A. eetr
- B. tree
- C. rtee
- D. eert
Correct answer: A. eetr
most_common lists e first because it occurs twice, and then t and r in first-seen order, each with one copy. Joining c times n gives eetr.
More Python Programming questions
- What is printed? python import itertools print(len(set(itertools.permutations('aab'))), len(list(itertools.permutations('aab'))))
- What is printed? python print(list(zip([iter(range(6))] 2)))
- What is printed? python print(sum(range(106)) % 7)
- What is printed? python print(12 & -12, 12 ^ 12 >> 1)
- What is printed? python print(list(map(lambda a, b: a b, [1, 2, 3], [4, 5])))
- What is printed? python print(max([], default=-1), min(range(0), default='e'))