ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools it = itertools.count(10, 5) print(list(itertools.islice(it, 3)), next(it))
- A. [10, 15, 20] 25
- B. [10, 15, 20] 20
- C. [10, 15, 20] 30
- D. [10, 15] 20
Correct answer: A. [10, 15, 20] 25
count(10, 5) yields 10, 15, 20, 25, and so on. islice takes the first three values, and the next value from the same iterator is the fourth one, 25.
More Python Programming questions
- What is printed? python words = ['b', 'a', 'c'] pairs = list(zip(sorted(words), range(10, 13))) print(pairs, dict(pairs)['c']…
- What is printed? python s = 'aabbbc' out = [] i = 0 while i < len(s): j = i while j < len(s) and s[j] == s[i]: j += 1 out.append(s[i] +…
- What is printed? python import math print(math.comb(10, 3) % 7, math.perm(5, 2), math.factorial(5) // math.factorial(3))
- What is printed? python x = [1, 2, 3] it = iter(x) print(next(it), sum(it), list(it))
- What is printed? python def tri(n): return n (n + 1) // 2 print(tri(10), tri(0), [tri(k) for k in range(4)])
- What is printed? python def f(xs): xs.sort() return xs data = [3, 1, 2] res = f(data) print(data is res, data)