ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE
What does the following Python 3 code print? a, b = [1,6,5,3], [8,3,5,8] print(list(map(lambda p: p[0] * p[1], zip(a, b))), len(list(zip(a, b))))
- A. [24, 15, 30, 8] 4
- B. [3, 30, 40] 3
- C. 75 4
- D. [8, 18, 25, 24] 4
Correct answer: D. [8, 18, 25, 24] 4
zip stops at the shorter input, so only min(len(a), len(b)) pairs are produced. Output: [8, 18, 25, 24] 4.
More Python Programming questions
- What is printed? python def k(a, b=(1, 2)): return b print(k(1) is k(2))
- What is printed? python class Box: def init(self, items=[]): self.items = items b1 = Box() b2 = Box() b1.items.append(1) print(b2.items)
- What is printed? python print({x: x 2 for x in range(-2, 3)})
- What is printed? python data = [1, 2, 2, 3, 3, 3] print({x for x in data if x > 1})
- What is printed? python print([[y for y in range(x)] for x in range(4)])
- What is printed? python print(list(x for x in range(5) if x % 2 == 0)[1:3])