ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(list(filter(lambda x: x > 0, map(lambda x: x - 2, [1, 2, 3, 4]))))
- A. [-1, 0, 1, 2]
- B. [1, 2]
- C. [1, 2, 3]
- D. [0, 1, 2]
Correct answer: B. [1, 2]
map subtracts 2 from each item, giving -1, 0, 1 and 2, and filter keeps the positive results, which are 1 and 2.
More Python Programming questions
- What is printed? python print(1e3, 1000.0 == 1e3, 10 -2)
- What is printed? python print(type(True + 1).name, type(2 1.0).name)
- What is printed? python print(list(enumerate(['x'], 1))[0][0] + 1)
- What is printed? python print(list('ab') == ['a', 'b'], 'ab' == ['a', 'b'])
- What is printed? python print(len(dict.fromkeys('aab')), list(dict.fromkeys('aab')))
- What is printed? python print([x for x in [1, 2, 3] for in range(x)])