ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools
print(sum(1 for t in itertools.product('01', repeat=10) if t.count('1') == 3))- A. 45
- B. 240
- C. 120
- D. 210
Correct answer: C. 120
Choosing which 3 of the 10 positions hold a 1 gives C(10, 3) = 120. Counting by the 10 positions alone or by pairs of ones would be the usual wrong reasoning.
More Python Programming questions
- What is printed? python import itertools g = itertools.groupby('aab') k, grp = next(g) next(g) print(k, list(grp))
- What is printed? python import itertools g = iter(range(10)) print(list(itertools.islice(g, 2, 7, 2)), next(g))
- What is printed? python import itertools print(list(itertools.ziplongest('ab', 'xyz', fillvalue='-')))
- What is printed? python import itertools print(sum(a < b for a, b in itertools.pairwise([1, 3, 2, 5, 4, 6])))
- What is printed? python import itertools print(list(itertools.batched(range(7), 3))[-1])
- What is printed? python import sys print(sys.getrecursionlimit())