Fix is always available.
This rule is unstable and in preview. The
--preview flag is required for use.
What it does#
Checks for the use of
sum() to flatten lists of lists, which has
Why is this bad?#
The use of
sum() to flatten lists of lists is quadratic in the number of
sum() creates a new list for each element in the summation.
Instead, consider using another method of flattening lists to avoid quadratic complexity. The following methods are all linear in the number of lists:
functools.reduce(operator.iconcat, lists, )
[item for sublist in lists for item in sublist]