Method Match
Lists are Mutable! Drag the Python code (left) to match its description (right).
Code / Method
Description / Effect
Interactive List Modifier
See list methods in action! Use the controls below to modify the list. Watch how it changes.
Current List:
Notice how the *original* list is changed directly. That's Mutability!
Predict the Final List
Read the Python code below. What will the list `data` look like *after* all the operations? Type your prediction exactly (e.g., [1, 'new', 3]
).
Choose the Right Tool
For each task described below, click the best Python tool (method or statement) to accomplish it.
List Challenges
Apply your knowledge! Write Python code to solve these list modification challenges. Check your solution after writing the code.
Challenge 1: Add to End
You have the list below. Write one line of Python code to add the string "d"
to the end of the list `items`.
Initial list: items = ['a', 'b', 'c']
Challenge 2: Insert at Start
Start with the list below. Add the number 0
to the very beginning (index 0) of the list `nums`.
Initial list: nums = [1, 2, 3]
Challenge 3: Remove by Value
From the list `mix` below, remove the first occurrence of the value "remove_me"
.
Initial list: mix = [10, "hello", "remove_me", 20]
Challenge 4: Remove by Index
Given the list `elements`, remove the item at index 2
(which is "C"
) using either del
or the .pop()
method.
Initial list: elements = ["A", "B", "C", "D"]
Challenge 5: Replace with Slice
Start with the list `letters`. Replace the elements from index 1 up to (but not including) index 3 (i.e., ['b', 'c']
) with the new list ['X', 'Y']
using slicing.
Initial list: letters = ['a', 'b', 'c', 'd']
Expected result: ['a', 'X', 'Y', 'd']
Module 11 Practice Complete!
Excellent! You've practiced manipulating lists and seen mutability in action.
Ready for more? Try the Advanced Practice for Module 11!