thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

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

All courses

Python 3: Lists / 02.04

List editing challenge

Not started

Complete all three original adding/removing tasks with clear checkpoints.

More options

Your lesson progress

Walkthrough: not startedPractice: not started

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.

Rob adds a city, removes a number into a separate tray, then compares an empty list with a deleted name.
Rob’s comic strip · Unpack and edit lists

ORIGINAL WALKTHROUGH · 10:57

Watch with Rob.

Pause whenever you want to try a change. You can return to the lesson at any time.

LEARN WITH THE CODE ZONE

Unlock this video walkthrough

Written lessons and coding practice are free. Video walkthroughs are included with a paid Code Zone membership or an active free trial.

Have a Code Zone website account? Use your learning account’s email to get a six-digit sign-in code, or use your existing website password.

Need a website account? Paid Skool members and active trial members can use the email from their membership questions to request a sign-in code. No invite link or Skool password needed.

Close this window to keep practicing. After signing in, you’ll return to this lesson.

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)

Starter source code for VS Code

Copy the source below or download the file to follow along in VS Code.

The download includes a lesson link in each file and a README so you can find your way back.

main.py
main.pypython · example
# Code along with Rob: List editing challenge
# Create four cities, append one and insert another in the second position; print each change.
# Pop and save the last of six numbers, then remove another value.
# Clear five items, re-create them, then delete their name and observe the difference.
# Predict each result, then press play.

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.

Expected output
['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.

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.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

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)

Continue learning

ONE STEP FORWARD

A cleared name still refers to an empty list. A deleted name is unavailable, and pop’s returned value can be saved.