ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE
What does the following Python 3 code print? a, b = [3,1,8,5,4,7], [7,4,2,5] print(list(map(lambda p: p[0] * p[1], zip(a, b))), len(list(zip(a, b))))
- A. 66 6
- B. [12, 2, 40] 3
- C. [21, 4, 16, 25] 4
- D. [10, 5, 10, 10] 4
Correct answer: C. [21, 4, 16, 25] 4
zip stops at the shorter input, so only min(len(a), len(b)) pairs are produced. Output: [21, 4, 16, 25] 4.
More Python Programming questions
- What does the following Python 3 code print? d = {} for w in ["kheer","ghee","bun","nut","cake","jam"]: d[w[0]] = d.get(w[0], 0) + 1…
- What does the following Python 3 code print? a, b = 18, 5 print(a // b, a % b, -a // b, -a % b)
- What does the following Python 3 code print? a = [[0] 2] 2 a[0][0] = 7 print(a)
- What does the following Python 3 code print? print(sum(x x for x in range(30) if x % 4 == 1))
- What does the following Python 3 code print? def f(x, acc=[]): acc.append(x) return acc f(8) f(4) print(f(8))
- What does the following Python 3 code print? fs = [lambda: i 2 for i in range(4)] print([f() for f in fs])