ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
from functools import reduce
print(reduce(lambda acc, ch: acc * 10 + int(ch), '2024', 0), reduce(lambda acc, ch: acc + ch, ['a', 'b'], 'x'))
  1. A. 2024 xba
  2. B. 2024 abx
  3. C. 2402 xab
  4. D. 2024 xab

Correct answer: D. 2024 xab

The first reduce builds the number digit by digit from left to right, giving 2024. The second starts from x and appends a and then b, giving xab.

More Python Programming questions

Exams that ask this topic