Aller au contenu

Large collection copy (ARCH2086)

Ce contenu n’est pas encore disponible dans votre langue.

Key python.performance.large-collection-copy · Severity info · Category performance

Fully materializing a generator with list() just to iterate it pulls every element into memory. Stream over the generator directly instead.

def total_amount(rows):
items = list(r.amount for r in rows)
return sum(items)
def total_amount(rows):
return sum(r.amount for r in rows)

Do not list() generators you only iterate; stream over them directly.