-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Enhancement ✨Improvement to a componentImprovement to a componentGood first issueFriendly and approachable by new contributorsFriendly and approachable by new contributors
Milestone
Description
Problem:
There are many cases of comprehensions inside of any
or all
calls that are unnecessary and should be replaced by a generator.
For example:
some_list = list(range(1000))
test_old = any([x % 7 == 0 for x in some_list])
Instead, a generator would be less code, and way faster:
test_new = any(x % 7 == 0 for x in some_list)
Speed comparisons:
64 µs ± 1.67 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) # old
447 ns ± 3.48 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) # new
any
and all
are functions that profit from that because the loop is breaking and can short cut; the remaining elements are not even looped over if the test returns a True
in the any
function or a False
in the all
function.
ioah86
Metadata
Metadata
Assignees
Labels
Enhancement ✨Improvement to a componentImprovement to a componentGood first issueFriendly and approachable by new contributorsFriendly and approachable by new contributors