ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
from itertools import accumulate
print(list(accumulate([1, 2, 3], lambda a, b: a * b)), list(accumulate('ab', initial='>')))- A. [1, 2, 6] ['>', '>a', '>ab']
- B. [1, 3, 6] ['>', '>a', '>ab']
- C. [1, 2, 6] ['x', 'xa']
- D. [1, 2, 6] ['>', 'a', 'b']
Correct answer: A. [1, 2, 6] ['>', '>a', '>ab']
accumulate with a multiplying function gives running products 1, 2, 6. initial='>' puts the start value first, and each step appends the next character to the running string.
More Python Programming questions
- What is printed? python print(sorted({'b': 1, 'a': 1}.items()), list({3: 'x', 1: 'y'}), dict(zip('ab', [1, 2])), dict.fromkeys('ab', 0))
- What is printed? python print(len({1, 1.0, True, '1'}), len({'1', 1}), {1, 2} == {2.0, 1.0}, {0} == {False})
- What is printed? python print(float('1' + '0' 308) == 1e308, 10 308 > 1e308, 10 308 < 1e308)
- What is printed? python from functools import reduce print(reduce(lambda acc, ch: acc 10 + int(ch), '2024', 0), reduce(lambda acc, ch: acc…
- 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)