Skip to content

Commit

Permalink
Change quadratic-list-summation docs to use iadd consistently (#1…
Browse files Browse the repository at this point in the history
…0666)

Closes #10088.
  • Loading branch information
charliermarsh authored Mar 30, 2024
1 parent 3c48913 commit 7c2e9f7
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ use crate::importer::ImportRequest;
/// quadratic complexity. The following methods are all linear in the number of
/// lists:
///
/// - `functools.reduce(operator.iconcat, lists, [])`
/// - `functools.reduce(operator.iadd, lists, [])`
/// - `list(itertools.chain.from_iterable(lists))`
/// - `[item for sublist in lists for item in sublist]`
///
/// When fixing relevant violations, Ruff defaults to the `functools.reduce`
/// form, which outperforms the other methods in [microbenchmarks].
///
/// ## Example
/// ```python
/// lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Expand All @@ -41,12 +44,14 @@ use crate::importer::ImportRequest;
///
///
/// lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
/// functools.reduce(operator.iconcat, lists, [])
/// functools.reduce(operator.iadd, lists, [])
/// ```
///
/// ## References
/// - [_How Not to Flatten a List of Lists in Python_](https://mathieularose.com/how-not-to-flatten-a-list-of-lists-in-python)
/// - [_How do I make a flat list out of a list of lists?_](https://stackoverflow.com/questions/952914/how-do-i-make-a-flat-list-out-of-a-list-of-lists/953097#953097)
///
/// [microbenchmarks]: https://github.com/astral-sh/ruff/issues/5073#issuecomment-1591836349
#[violation]
pub struct QuadraticListSummation;

Expand Down

0 comments on commit 7c2e9f7

Please sign in to comment.