ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
from functools import reduce print(reduce(lambda a, b: a + b, ['x', 'y', 'z'], ''), reduce(lambda a, b: a * b, range(1, 6)))
- A. xyz 60
- B. zyx 120
- C. xyz 24
- D. xyz 120
Correct answer: D. xyz 120
With an empty initial value, reduce concatenates the strings in order. The product of 1 through 5 is 120.
More Python Programming questions
- What is printed? python print(0.1 + 0.2 > 0.3, 0.3 - 0.1 == 0.2, 0.2 + 0.2 == 0.4, 0.4 - 0.2 == 0.2)
- What is printed? python from collections import defaultdict d = defaultdict(int) for w in 'a b a c'.split(): d[w] += 1…
- What is printed? python print(sum([1e100, 1.0, -1e100]) == 1.0, sum([1, 1e100, -1e100]), 1e100 + 1.0 - 1e100)
- What is printed on the third line? python emp = [('Ravi', 30, 'IT'), ('Asha', 25, 'HR'), ('Meera', 30, 'HR'), ('Dev', 25, 'IT')] byage =…
- What is printed on the second line? python items = [3, -1, 2, -3, 1] print(sorted(items, key=abs)) print(sorted(items, key=abs…
- What is printed on the second line? python data = [('b', 2), ('a', 2), ('c', 1), ('a', 1)] print(sorted(data, key=lambda t: (t[1], t[0])…