Min, Max, Sum & Running Totals
Aggregate a list in a single pass.
Aggregate in One Pass
Many problems just need a single number from an array. Python's built-ins do this aggregation in one fast pass over the list.
a = [4, 1, 7, 3]Sum It Up
sum(a) adds every element and returns the total. It is C-fast, so prefer it over writing your own accumulation loop.
total = sum(a) # 15All lessons in this course
- Lists, Indexing & Slicing for CP
- Build Arrays Fast with Comprehensions
- Min, Max, Sum & Running Totals
- Find the Index, Not Just the Value