ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
data = "2\n10 20\n30\n" it = iter(data.split()) n = int(next(it)) arr = [int(next(it)) for _ in range(n)] print(arr, next(it, 'none'))
- A. [10, 20] 30
- B. [10, 20] 2
- C. [2, 10] 30
- D. [10, 20] none
Correct answer: A. [10, 20] 30
The token iterator reads n = 2 first, then the next two tokens 10 and 20. The third token is still unread, so next(it, 'none') returns '30'. Token iterators are the standard way to read mixed-length input.
More Python Programming questions
- What is printed? python from operator import itemgetter rows = [('b', 2, 'x'), ('a', 2, 'y'), ('c', 1, 'z')] print([r[0] for r in…
- What is printed? python import bisect print(bisect.bisect([1, 2, 2, 5], 2))
- What is printed? python try: sorted([3, 'a']) except TypeError as e: print(e)
- A Python solution reads n = 10^6 numbers with input() in a loop, calling int(input()) for each line. Which change is the most effective…
- What is printed? python import math print(math.gcd(12, 18, 27), math.lcm(4, 6), math.gcd())
- What is printed? python print(divmod(-(10 20), 7))