$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · medium · #244

What is the output?

nums = [1, 5, 8, 3]
print([y for x in nums if (y := x * 2) > 6])
  1. [16]
  2. [5, 8]
  3. [10, 16]
  4. [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 ▸