Python/Collections 7 min
Lists and loops
Ordered collections and the for loop that walks them.
listfor loopcomprehension
A list is an ordered, mutable sequence. You append to it, index into it and slice it.
python · editable
loading editor…
A for loop iterates over any sequence. enumerate gives you the index alongside the value, and zip walks two sequences in step.
python · editable
loading editor…
A list comprehension builds a new list from an old one in a single expression, with an optional filter — it replaces most short accumulation loops.
python · editable
loading editor…
practice this