What is the expected output?
MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.
What is the expected output?
print(list(map((lambda x:x**3), filter((lambda x:x%2==0), range(5,-5,-2)))))
Pick ONE option
Show answer & explanation
Answer: B. []
range(5, -5, -2) generates [5, 3, 1, -1, -3]. The filter(lambda x: x%2==0, ...) keeps only even numbers, but all values in this range are odd, so the filter produces an empty sequence. map() then has nothing to operate on, resulting in an empty list [].
Step-by-step Derivation:
Step 1: Evaluate range(5, -5, -2)
- Start: 5, Stop: -5, Step: -2
- Sequence: [5, 3, 1, -1, -3]
Step 2: Apply filter(lambda x: x%2==0, ...)
- Check 5 % 2 == 0? → False (5 is odd)
- Check 3 % 2 == 0? → False (3 is odd)
- Check 1 % 2 == 0? → False (1 is odd)
- Check -1 % 2 == 0? → False (-1 is odd)
- Check -3 % 2 == 0? → False (-3 is odd)
- Filter result: [] (no even numbers)
Step 3: Apply map(lambda x: x**3, [])
- No elements to map over
- Map result: []
Step 4: Convert to list and print
- Output: []