4 ms·
Or: validated_items = [x for x in items if is_validated(x)]
by graton 10y ago
Or:
validated_items = [x for x in items if is_validated(x)]
- im3w1l 10y agoI prefer the other one, because then I don't have to consider whether there is an outer variable 'x' that is being clobbered.
- Singletoned 10y agoMost 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).
- aidos 10y agoIn python 3, x is locally scoped to the comprehension :-)