Describe the accumulation pattern for building a list of the squares of the integers 1 through 5 using a for loop.
Think about your answer, then reveal below.
Model answer: Initialize an empty list before the loop (e.g., squares = []). Inside a for loop over range(1, 6), append i**2 to the list each iteration. After the loop, squares holds [1, 4, 9, 16, 25].
The accumulation pattern separates creation from computation: start with an empty container, iterate over inputs, and collect results one at a time. It is the foundational pattern for transforming sequences and appears in list comprehensions, map operations, and reduce operations — all of which are built on this same idea.