ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import itertools rows = [[1, 2], [3], [4, 5, 6]] print(sum(len(r) for r in rows), list(itertools.chain(*rows))[-1], max(map(len, rows)))
- A. 6 4 3
- B. 6 6 2
- C. 5 6 3
- D. 6 6 3
Correct answer: D. 6 6 3
The three rows have 2, 1 and 3 items, which is 6 in total. chain flattens the rows, so the last item is 6. The longest row has 3 items.
More Python Programming questions
- What is printed? python x = 10 def g(): print(x) x = 20 try: g() except UnboundLocalError as e: print(type(e).name)
- What is printed? python print(0.1 + 0.2 > 0.3, 0.5 + 0.25 == 0.75, 1 / 3 3 == 1.0)
- What is printed? python words = ['pear', 'fig', 'banana'] index = {w: i for i, w in enumerate(words)} print(index['fig']…
- What is printed? python s = {1, 2, 3} t = s t |= {4} u = s | {5} print(len(s), len(u), t is s)
- What is printed? python def gen(): x = yield 1 print('got', x) yield 2 g = gen() print(next(g)) print(g.send('hi'))
- What is printed? python print(sum(1 for c in 'Mississippi' if c in 'aeiou'), 'Mississippi'.count('ss'), 'Mississippi'.rfind('ss'))