Why this matters
Single source of truth reduces bugs and accelerates changes.
Move repeated sequences of operations into named helpers or utilities and reuse them.
Single source of truth reduces bugs and accelerates changes.
Side-by-side examples engineers can pattern-match during review.
total = sum(i['p']*i['q'] for i in items)
...
other_total = sum(i['p']*i['q'] for i in items2)def line_total(i: dict) -> float:
return i['p'] * i['q']
def sum_total(items: list[dict]) -> float:
return sum(line_total(i) for i in items)same expression pasted everywheredef helper(...): ...From the same buckets as this rule.