You’ll be able to
- Create, index, and modify lists in place
- Iterate over lists with
forandenumerate() - Add and remove items with
append(),pop(),remove() - Sort lists in place and get sorted copies with
sorted()
Loading lesson…
Why this matters
Lists are the default container in every Python codebase, and for loops drive everything from ETL pipelines to ML training epochs. Understanding iteration is the difference between shipping code and copy-pasting Stack Overflow.
Common pitfalls
- Mutating a list while iterating:
for x in lst: lst.remove(x)skips elements. Iterate overlst[:]or build a new list. - Using
list = [1,2,3]as a variable name. It shadows the built-in and breakslist(range(5))later. - Assuming
a = bcopies the list. It aliases; usea = b.copy()ora = b[:]to duplicate.