Learn
Python Lists and Dictionaries
Remove a Few Things
Sometimes you need to remove something from a list.
beatles = ["john","paul","george","ringo","stuart"] beatles.remove("stuart") print beatles
This code will print:
["john","paul","george","ringo"]
- We create a list called
beatles
with 5 strings. - Then, we remove the first item from
beatles
that matches the string"stuart"
. Note that.remove(item)
does not return anything. - Finally, we print out that list just to see that
"stuart"
was actually removed.
Instructions
1.
Remove 'dagger'
from the list of items stored in the backpack
variable.