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'))
- A. 2024 xba
- B. 2024 abx
- C. 2402 xab
- 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
- What is printed? python print('{0:>{1}}'.format('x', 3), '{:0>3}'.format(7), '{:x<4}'.format('ab'), '{:^7.3f}|'.format(2.5))
- What is printed? python print(1 == True == 1.0, 2 > 1 == True, (2 > 1) == True, 1 < 2 == True)
- What is printed? python print(int(' 0x1f ', 16), int('1e3', 16), float('1e3'))
- What is printed? python from collections import Counter c = Counter(['x', 'y', 'x', 'z', 'y', 'x']) print(c.mostcommon()…
- What is printed? python print(10 % 3 2, 10 % (3 2), (10 % 3) 2, -10 % 3 2)
- What is printed? python print(list(range(10, 0, -3)), list(range(-1, -10, -4)), len(range(0, 10, 3)), range(5)[-1])