ProgrammingHardInfosys · Python
What is printed?
What is printed?
m = map(lambda x: x * 2, [1, 2, 3]) print(list(m), list(m), sum(map(int, '123')))
- A. [2, 4, 6] [2, 4, 6] 6
- B. [2, 4, 6] [] 6
- C. [1, 2, 3] [] 6
- D. [2, 4, 6] [] 123
Correct answer: B. [2, 4, 6] [] 6
A map object is a one-shot iterator: the first list() exhausts it, so the second gives []. The sum of the digits 1, 2, 3 is 6.
More Python Programming questions
- What is printed? python class P: def init(self, v): self.v = v def eq(self, o): return self.v == o.v try: s = {P(1), P(1)} print(len(s))…
- What is printed? python fs = [lambda x, i=i: x i for i in range(3)] gs = [lambda x: x i for i in range(3)] print([f(2) for f in fs], [g(2)…
- What is printed? python n = 1 xs = [1, 2, 3] g = (x for x in xs if x > n) xs = [10, 20] n = 2 print(list(g))
- What is printed? python print(f"{255:#x} {255:08b} {3.14159:.2f} {'ab':>4}|{12345.678:,.1f}")
- What is printed? python def fib(n, memo={}): if n < 2: return n if n not in memo: memo[n] = fib(n - 1) + fib(n - 2) return memo[n]…
- What is printed? python class T: def init(self, n): self.n = n def enter(self): print('in', self.n, end=' ') return self def exit(self…