The list is Python’s array: ordered, mutable, indexed from 0. Master its costs and half of DSA becomes bookkeeping.
1 Indexing is O(1)
nums[3] jumps straight to slot 3 — the list stores its elements in one contiguous block with the length on the side.
2 Inserting is O(n)
nums.insert(2, 25) shifts every element from index 2 rightward. On a 10,000-element list at the front, that is 10,000 moves.
3 append is O(1) amortised
Python over-allocates spare slots, so appending usually touches one slot. insert(0, x) is the O(n) villain.
4 Slices copy
nums[1:4] builds a NEW list of three elements — the stop index is excluded, so the length is stop − start.
5 Assignment aliases
b = a copies the reference, not the list. Two names, one object — append through b and a sees it too. Use a.copy() to escape.
The workhorse container
Indexing is O(1)1nums[3] jumps straight to slot 3 — the list stores its elements in one contiguous block with the length on the side. Inserting is O(n)2nums.insert(2, 25) shifts every element from index 2 rightward. On a 10,000-element list at the front, that is 10,000 moves. append is O(1) amortised3Python over-allocates spare slots, so appending usually touches one slot. insert(0, x) is the O(n) villain. Slices copy4nums[1:4] builds a NEW list of three elements — the stop index is excluded, so the length is stop − start. Assignment aliases5b = a copies the reference, not the list. Two names, one object — append through b and a sees it too. Use a.copy() to escape. 5 building blocks make up The workhorse container
insert(2, 25) must shove 30 and 40 right first — then append lands free.
1 / 9nums = [10, 20, 30, 40] plus one spare slot. Target: 25 at index 2, between 20 and 30.
Every scan, sum and extrema hunt is this loop wearing a different hat.
process decision input / output start / end A hand-rolled minimum scan, then the append / insert / slice / remove toolbox in one script.
moduleFive scores, no order required.
Memory
scores= [34, 12, 8, 27, 15]
Console
output appears as the program runs…
nums[1:4] — the start is in, the stop is a wall. Negative indexes count from the end.
1 / 8nums = [10, 20, 30, 40, 50, 60]. A slice asks for a run of cells — we want nums[1:4].
Two names, one list — aliasing in three lines.
Your predicted output — one line per console line
Hint: b = a copies the reference, not the list. Appending through b is visible through a — and a is b is True.
Click a term, then click its meaning to lock the pair.
8 conceptsTap a card to expand ?append(x)drops into place
?insert(0, x)drops into place
?nums[1:4]drops into place
?b = adrops into place
?a.copy()drops into place
?len(a)drops into place
?queue[-1]drops into place
?del a[2]drops into place
01Indexing is O(1); inserting or deleting in the middle is O(n) because neighbours shift.
02append is amortised O(1) — Python over-allocates spare slots at the end.
03The slice stop is exclusive: nums[1:4] has length 3, not 4.
04b = a aliases; use a.copy() or a[:] when you need an independent list.
05for item in nums walks values; range(len(nums)) walks indexes — prefer the first unless you need i.
06min(), max() and sum() replace hand-rolled scans when a plain pass is enough.