manual-list-copy (PERF402)
Added in v0.0.276 · Related issues · View source
Derived from the Perflint linter.
What it does
Checks for for loops that can be replaced by a making a copy of a list.
Why is this bad?
When creating a copy of an existing list using a for-loop, prefer
list or list.copy instead. Making a direct copy is more readable and
more performant.
Using the below as an example, the list-based copy is ~2x faster on
Python 3.11.
Note that, as with all perflint rules, this is only intended as a
micro-optimization, and will have a negligible impact on performance in
most cases.
Example
Use instead: