Hacker News new | ask | show | jobs
by graton 3393 days ago
Or:

validated_items = [x for x in items if is_validated(x)]

1 comments

I prefer the other one, because then I don't have to consider whether there is an outer variable 'x' that is being clobbered.
In python 3, x is locally scoped to the comprehension :-)
Most linters would have suggested correcting it to:

validated_items = [_ for _ in items if is_validated(x)]

where _ is used as a safe variable that can always be clobbered. (Though this does also clash with its use as a gettext function for strings).