Work with real shapes of data / CORE PATH
Loops & accumulation
Iteration applies a rule repeatedly while preserving an invariant.
A row loop is useful for learning. Later compare it with SQL and pandas operations.
Understand the idea
Iteration applies a rule repeatedly while preserving an invariant. A row loop is useful for learning. Later compare it with SQL and pandas operations.
Work through the practice with a tiny fixture, predict the result before running it, and record one boundary case. Use the exit check as evidence before moving on.
What to learn
- Use for, range, enumerate, break and continue.
- Accumulate a total with a clear initial value.
- Trace a loop on an empty input and a single record.
A small original example
total = 0
for amount in [None, 0, -2, 10]:
if amount is not None and amount >= 0:
total += amount
print(total)Practice on your own data
Task 08: sum only nonmissing, nonnegative integer amounts.
Practice this lesson in the Python lab →
valid_total([None, 0, -2, 10]) is 10.
Common pitfalls
- Changing a list while iterating over it can skip entries.
- A while loop needs a path toward termination.
Prerequisites
Boot.dev chapter 8 · 03:24:46 ↗
Video and playlist companions
Choose one explanation for the concept, then attempt the practice. These are topic mappings, not a claim that every linked lesson covers every outcome.
Boot.dev · Python for Beginners
Loads YouTube on request. Open on YouTube ↗ if the owner restricts embedding.
كورس Python منحة ITI
Loads YouTube on request. Open on YouTube ↗ if the owner restricts embedding.
Python - The Basics - Part 1 | جحر السوعبان
Loads YouTube on request. Open on YouTube ↗ if the owner restricts embedding.
Sources and further reading
- Boot.dev · Python for Beginners ↗User-selected YouTube course
- كورس Python منحة ITI ↗User-selected ITI playlist
- Harvard CS50P · lectures & problem sets ↗User-selected HarvardX CS50P course
- Python language tutorial ↗Official documentation
- Python - The Basics - Part 1 | جحر السوعبان ↗User-selected YouTube resource
Track progress on this topic → · Markdown source ↗