T
Terry Reedy
for each item in the iterable.
No, as regards my post. I simply made a factual statement without
advocating a particular action.
filter(lambda x: <expr>, iterable)
(x for x in iterable if <expr>)
both create iterators that produce the items in iterable such that
2.60
Simply keeping true items is faster with filter -- at least on my
particular machine with 3.3.0b2.
1.03
Filter is also faster if the expression is a function call.
f=lambda i: False")
2.5033614114454394f=lambda i: False")
3.2394095327040304
---
Perhaps or even yes as regards the so-called rule 'always use
comprehension'. If one prefers filter as more readable, if one only
wants to keep true items, if the expression is a function call, if
evaluating the expression takes much more time than the extra function
call so the latter does not matter, if the number of items is few enough
that the extra time does not matter, then the rule is not needed or even
wrong.
So I think PyLint should be changed to stop its filter fud.
A case of premature optimisation?
No, as regards my post. I simply made a factual statement without
advocating a particular action.
filter(lambda x: <expr>, iterable)
(x for x in iterable if <expr>)
both create iterators that produce the items in iterable such that
"ranger=range(20)")"ranger=range(0)")
0.83
2.60
Simply keeping true items is faster with filter -- at least on my
particular machine with 3.3.0b2.
1.03
Filter is also faster if the expression is a function call.
f=lambda i: False")
2.5033614114454394f=lambda i: False")
3.2394095327040304
---
Perhaps or even yes as regards the so-called rule 'always use
comprehension'. If one prefers filter as more readable, if one only
wants to keep true items, if the expression is a function call, if
evaluating the expression takes much more time than the extra function
call so the latter does not matter, if the number of items is few enough
that the extra time does not matter, then the rule is not needed or even
wrong.
So I think PyLint should be changed to stop its filter fud.