Lists, Indexing & Slicing for CP
Access, slice, and reverse without off-by-one.
Your Contest Workhorse
In competitive Python, the list is your go-to array. It stores items in order and grows as needed, so most problems start here.
a = [4, 1, 7, 3]Indexing from Zero
Lists use zero-based indexing, so a[0] is the first item. Forgetting this is the classic off-by-one bug that costs easy points.
a = [4, 1, 7, 3]
print(a[0]) # 4All 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