What is the output?
nums = [1, 5, 8, 3] print([y for x in nums if (y := x * 2) > 6])
- [16]
- [5, 8]
- [10, 16]
- [2, 10, 16, 6]
The walrus assigns y = x * 2 inside the filter, so the kept values are the doubled ones above 6: 10 and 16.
Play Problem Solving ▸