ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from itertools import chain print(list(chain.from_iterable(['ab', 'c'])), ''.join(chain(*[['x'], ['y', 'z']])))
- A. ['a', 'b', 'c'] xyz
- B. ['ab', 'c'] xyz
- C. ['a', 'b', 'c'] x y z
- D. ['ab', 'c'] xy
Correct answer: A. ['a', 'b', 'c'] xyz
chain.from_iterable flattens one level, and a string is iterated character by character, so the result is ['a', 'b', 'c']. chain(*...) flattens the nested lists, which join to xyz.
More Python Programming questions
- What is printed? python print(repr("it's"), repr('say "hi"'), len('x41101'), len(r'n'))
- What is printed? python print(pow(3, -1, 8)) try: print(pow(4, -1, 8)) except ValueError: print('not invertible')
- What is printed? python import math print(math.comb(100, 50) % 1000, 2100 % 9, sum(map(int, str(2100))) % 9)
- What is printed? python print(5e-324 / 2 == 0, 2e-323 > 5e-324, float('1e-400'), 5e-324 / 2 == 0.0)
- What is printed? python import math print(int(-0.5), int(-1.9), math.floor(-1.1), round(-1.5))
- What is printed? python print(7 & -8, 7 | -8, 7 ^ -8, ~7 & 0xFF)