What is the output of print(list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4]))) in Python?
print(list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4])))
Correct answer
D. [2, 4]
D. [2, 4]
filter() keeps items for which the function returns a truthy value.
Asked in: Python Interview Functions
https://docs.python.org/3/tutorial/controlflow.html#defining-functionsNot sure why the answer is D? Ask here and get an explanation.