ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(list(zip([1, 2, 3], 'ab')), list(zip('ab', [1, 2, 3], [True])), len(list(zip())))- A. [(1, 'a'), (2, 'b'), (3, None)] [('a', 1, True)] 0
- B. [(1, 'a'), (2, 'b')] [('a', 1, True), ('b', 2, None)] 0
- C. [(1, 'a'), (2, 'b')] [('a', 1, True)] 0
- D. [(1, 'a'), (2, 'b')] [('a', 1, True)] 1
Correct answer: C. [(1, 'a'), (2, 'b')] [('a', 1, True)] 0
zip stops at the shortest iterable, so the first result has two pairs and the second has one. zip with no arguments yields nothing, so its length is 0.
More Python Programming questions
- What is printed? python try: list(zip([1, 2], [3], strict=True)) except ValueError: print('length mismatch') print(list(zip([1, 2], [3])))
- What is printed? python print([f'{i}{ch}' for i, ch in enumerate('ab', 1)])
- What is printed? python from itertools import groupby print([(k, len(list(g))) for k, g in groupby('aabbaa')])
- What is printed? python print('a,b'.split(',', -1), 'a,b,c'.split(',', 0), 'a b c'.split(maxsplit=1))
- What is printed? python print(bytes.fromhex('de ad'), (255).tobytes(2), bytes([1, 2]).hex(' '))
- What is printed? python print(round(1.5, 0), round(-2.5), round(2.5, 0) == 2, round(0.5, 0) == 0)