What is the output of `list(filter(lambda x: x > 10, [5, 12, 8, 20, 10]))` in Python?

Answer and explanation

Correct answer: D. [12, 20]

  1. Step 1: Apply the lambda predicate `x > 10` to each element in `[5, 12, 8, 20, 10]`.
  2. Step 2: Elements strictly greater than 10 are 12 and 20. The value 10 is excluded because is False. The filtered list is `[12, 20]`.
Answer
[12, 20].
Why not the others: `[12, 20, 10]` includes 10 (which is not strictly greater); `[5, 8, 10]` filters for ; `[True, False]` is a boolean mapping, not filtering.

Practise more Algorithms and Python Programming.

Free questions with an explanation for every one, and full timed EmSAT Achieve (UAE) mock tests.

What is the output of… | EmSAT Achieve (UAE)