Use a list when you need an ordered collection that can change. A grocery list is a familiar example: add items as you remember them, then remove them as you shop. Unlike a tuple, a list is mutable—you can change the same list object instead of making a new one. section 25.0 section 25.1
Create a list with square brackets: `grocery = ["milk", "eggs", "bread"]`. Use `[]` for an empty list. Positions, called indexes, start at 0: `grocery[0]` is `"milk"`, and `len(grocery)` is 3. Trying `grocery[3]` raises an `IndexError` because the last index is 2. section 25.2
Change a list without assigning a new list to its variable:
- `grocery.append("cheese")` adds one item at the end; `grocery.insert(1, "apples")` adds one at index 1 and shifts later items. `grocery.extend(other_list)` adds another list’s elements in order. section 25.4
- `grocery.pop()` removes and returns the last item. `grocery.pop(1)` removes and returns the item at index 1; later items shift left. section 25.5
- `grocery[0] = "oat milk"` replaces the first item. Subsequent operations use the changed list. section 25.6
Lists can hold different object types, including other lists. You can also sort or reverse a list, or split a string into a list. Be careful when two variables refer to the same mutable list: changing it through either name affects the shared object. Use `list(original)` or `original.copy()` when you need a separate list. section 26.0 section 26.5 section 28.0 section 28.2
Listing 26.5. A queue of people represented by a list
line = [] #1
line.append('Ana') #2
line.append('Bob') #3
line.pop(0) #4
line.append('Claire') #5
line.append('Dave') #5
line.pop(0) #6
line.pop(0) #6
line.pop(0) #6
Follow the queue one line at a time: `append()` places a person at the end, while `pop(0)` removes the person at the front. The list supplies the storage; the chosen operations give it queue behavior. section 26.4
Quick check: after `items = ["pen", "paper"]`, what are `items` and `removed` after `removed = items.pop(0)`? For a larger project, a list can hold the words split from a document before a dictionary counts how often each word appears. section 25.5 section 29.3 section 29.8




















