←back to thread

317 points est | 1 comments | | HN request time: 0.205s | source
1. Myrmornis ◴[] No.17450495[source]
From the PEP

  # Share a subexpression between a comprehension filter clause and its output
  filtered_data = [y for x in data if (y := f(x)) is not None]
What about

  filtered_data = [(y := f(x)) for x in data if y is not None]
will that work also?

Attempted guess at answer: no, because the "gathering" part of the comprehension is downstream of the "sequence construction" part of the comprehension in the language implementation. But if that's so, I'm a bit concerned that this will be confusing to users.