ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE
What does the following Python 3 code print? a, b = [8,5,9,9,3], [5,4,3,3] print(list(map(lambda p: p[0] * p[1], zip(a, b))), len(list(zip(a, b))))
- A. [40, 20, 27, 27] 4
- B. [13, 9, 12, 12] 4
- C. [15, 36, 27, 15] 5
- D. [32, 15, 27] 3
Correct answer: A. [40, 20, 27, 27] 4
zip stops at the shorter input, so only min(len(a), len(b)) pairs are produced. Output: [40, 20, 27, 27] 4.
More Python Programming questions
- What does the following Python 3 code print? fs = [lambda: i 5 for i in range(3)] print([f() for f in fs])
- What does the following Python 3 code print? d = {} for w in ["nut","kheer","tea","oat","nut","vada"]: d[w[0]] = d.get(w[0], 0) + 1…
- What does the following Python 3 code print? s = "banana split" print("-".join(s.split("n")[1:]))
- What does the following Python 3 code print? from functools import lrucache calls = 0 @lrucache(None) def f(n): global calls calls += 1…
- What does the following Python 3 code print? a, b = set([12,12,1,7,1]), set([12,12,3,10,6,10]) print(sorted(a ^ b), len(a - b))
- What does the following Python 3 code print? def mk(): c = 0 def inc(): nonlocal c c += 2 return c return inc a, b = mk(), mk() for in…