ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = [1, 2, 3] it = iter(x) print(next(it), sum(it), list(it))
- A. 1 5 []
- B. 1 5 [2, 3]
- C. 1 6 []
- D. 1 [2, 3] []
Correct answer: A. 1 5 []
next takes 1 from the iterator. sum consumes the rest, 2 and 3, giving 5, so the iterator is empty by the time list(it) runs.
More Python Programming questions
- 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)
- Which Python construct is the most efficient way to test whether a sorted list a contains x in O(log n) time without building extra…
- Which of the following problems can be solved correctly by a greedy algorithm that sorts by end time, when given the intervals and asked…
- What is printed? python a = [1, 2, 3, 4, 5, 6] print(a[1::2], a[::-2], a[4:1:-1])
- What is printed? python s = 'a1b22c333' import re print(re.findall(r'd+', s), sum(int(x) for x in re.findall(r'd+', s)))