02.04 · Unpack and edit lists / Practice · 11 min
Update cities, remove numbers and clear a list
Adding, removing, clearing and deleting are different changes. Inspect the result after each one.
Activity 4 of 4 in Unpack and edit lists
Python 3: Lists / 02.04
List editing challenge
Not started
Complete all three original adding/removing tasks with clear checkpoints.
Your lesson progress
Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

ORIGINAL WALKTHROUGH · 10:57
Watch with Rob.
Pause whenever you want to try a change. You can return to the lesson at any time.
You are signed in, but video access needs attention. Check your account access. Your saved work is kept.
Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.
Open video & code editor (opens in a new tab)Your task: add two cities
Keep the four starting cities. Append "Miami" and print cities. Insert "Paris" in the second position and print cities again. Remember that the second position has index 1.
Your task: remove and save
Keep the six starting numbers. Remove the last number using pop, assign that returned value to removed_number and print it. Print the remaining numbers, then remove the value 30 and print numbers again.
Your task: empty versus delete
Keep the five starting items. Clear items and print the empty list. Re-create the same five-item list, then delete its name with del items. Leave the supplied final verification lines in place; they print False when the name is no longer available.
The original task asks you to observe an error after deleting the name. To keep all automated checks running, our supplied verification reports the name’s absence instead of deliberately crashing. The reading explains the NameError you would see.
Review the original challenge
Checks compare fixed output and final named values, not the exact sequence of methods you typed. Check your source for append, insert, pop, remove, clear and del. After passing, try removing a different existing number; restore the original before checking again.
The original 10:57 challenge and its Solution Set are linked below, with a separate open workspace for following the recording.
Build it one step at a time
Prefer learning by typing? Work through short instructions, run the Python code and check each change before continuing. Your guided project saves separately from the challenge below.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)7 steps · Saved work · Instant feedback
YOUR TURN
Make each list change explicit
Append Miami; insert Paris second. Pop and save 60; remove 30. Clear items, re-create its five original values, then delete the name. Keep the supplied verification and print order.
['London', 'Tokyo', 'Rome', 'Oslo', 'Miami'] ['London', 'Paris', 'Tokyo', 'Rome', 'Oslo', 'Miami'] 60 [10, 20, 30, 40, 50] [10, 20, 40, 50] [] False
Keep the starting inputs. Print these lines in this order, without extra output.
- Store the requested cities
- Store the requested numbers
- Store the requested removed number
- Store the requested items still defined
- Output 1 matches the requested checkpoint
- Output 2 matches the requested checkpoint
- Output 3 matches the requested checkpoint
- Output 4 matches the requested checkpoint
- Output 5 matches the requested checkpoint
- Output 6 matches the requested checkpoint
- Output 7 matches the requested checkpoint
Edit Python, then run it. Check challenge checks your output and the listed Python requirements. Your code saves on this browser after a short pause. Sign in and choose Save account draft to keep it across devices. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Need a nudge?
Changing and returning are different
Call append and insert without replacing cities. Assign the result of numbers.pop() to removed_number.
Clear, rebuild, then delete the name
items.clear() leaves []. Reassign the five starting values, then use del items. The supplied globals check reports whether the name remains.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
Each print captures one moment in the program. Later mutations do not change earlier output, and deleting a name differs from emptying its collection.
Walk through the fix.
Choose Next to inspect one change at a time. Highlighted lines show what to notice. Your editor stays unchanged unless you choose to load a step.
Step 1 of 2
Read the original inputs
Keep the supplied inputs so each check has the same starting point.
cities = ["London", "Tokyo", "Rome", "Oslo"]Expected output for this step
(No output)
Trace each assignment and change
Each print captures one moment in the program. Later mutations do not change earlier output, and deleting a name differs from emptying its collection.
cities = ["London", "Tokyo", "Rome", "Oslo"]
cities.append("Miami")
print(cities)
cities.insert(1, "Paris")
print(cities)
numbers = [10, 20, 30, 40, 50, 60]
removed_number = numbers.pop()
print(removed_number)
print(numbers)
numbers.remove(30)
print(numbers)
items = ["pen", "book", "lamp", "cup", "key"]
items.clear()
print(items)
items = ["pen", "book", "lamp", "cup", "key"]
del items
# Supplied verification: leave these final lines unchanged.
items_still_defined = "items" in globals()
print(items_still_defined)Expected output for this step
['London', 'Tokyo', 'Rome', 'Oslo', 'Miami'] ['London', 'Paris', 'Tokyo', 'Rome', 'Oslo', 'Miami'] 60 [10, 20, 30, 40, 50] [10, 20, 40, 50] [] False
See the complete solution
cities = ["London", "Tokyo", "Rome", "Oslo"]
cities.append("Miami")
print(cities)
cities.insert(1, "Paris")
print(cities)
numbers = [10, 20, 30, 40, 50, 60]
removed_number = numbers.pop()
print(removed_number)
print(numbers)
numbers.remove(30)
print(numbers)
items = ["pen", "book", "lamp", "cup", "key"]
items.clear()
print(items)
items = ["pen", "book", "lamp", "cup", "key"]
del items
# Supplied verification: leave these final lines unchanged.
items_still_defined = "items" in globals()
print(items_still_defined)Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)