ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(list(enumerate('ab', start=1)), list(zip(reversed([1, 2, 3]), 'xyz')))- A. [(0, 'a'), (1, 'b')] [(3, 'x'), (2, 'y'), (1, 'z')]
- B. [(1, 'a'), (2, 'b')] [(3, 'x'), (2, 'y'), (1, 'z')]
- C. [(1, 'a'), (2, 'b')] [(1, 'x'), (2, 'y'), (3, 'z')]
- D. [(1, 'a'), (2, 'b'), (3, None)] [(3, 'x'), (2, 'y'), (1, 'z')]
Correct answer: B. [(1, 'a'), (2, 'b')] [(3, 'x'), (2, 'y'), (1, 'z')]
enumerate with start=1 counts from 1, and reversed walks the list backwards before zip pairs it with the string. zip stops at the shorter input.
More Python Programming questions
- What is printed? python print(hash(1) == hash(True), hash(-1) == -2)
- Which statement about dictionary iteration order in Python 3.7 and later is correct?
- What is printed? python class Q: def init(self): self.i, self.o = [], [] def push(self, x): self.i.append(x) def pop(self): if not self.o…
- What is printed? python print([y for x in [[1, 2], [3], []] for y in x if y % 2])
- What is printed? python out = [] for i in range(3): try: if i == 1: continue out.append(i) finally: out.append('f') print(out)
- What is printed? python print(int('0x1f', 16), int('1f', 16), int('0o17', 8))