Course Content
Python Data Structures
Python Data Structures
Removing Elements
Imagine you have this list:
tasks = ['email Ann', 'call Max', 'meet with classmates'] print(tasks)
You can also remove an item from the list by specifying its value. Here's how to do that.
tasks = ['email Ann', 'call Max', 'meet with classmates'] tasks.remove('call Max') print(tasks)
Now, the list is down to two items instead of three:
tasks[0]
reads'email Ann'
;tasks[1]
reads'meet with classmates'
.
Note
With the
remove()
method, you can only take out one item at a time.
Task
You've got this list:
numbers = [10, 12, 14, 16, 18, 20]
Your goal is to end up with:
numbers = [12, 14, 16]
Thanks for your feedback!
Removing Elements
Imagine you have this list:
tasks = ['email Ann', 'call Max', 'meet with classmates'] print(tasks)
You can also remove an item from the list by specifying its value. Here's how to do that.
tasks = ['email Ann', 'call Max', 'meet with classmates'] tasks.remove('call Max') print(tasks)
Now, the list is down to two items instead of three:
tasks[0]
reads'email Ann'
;tasks[1]
reads'meet with classmates'
.
Note
With the
remove()
method, you can only take out one item at a time.
Task
You've got this list:
numbers = [10, 12, 14, 16, 18, 20]
Your goal is to end up with:
numbers = [12, 14, 16]
Thanks for your feedback!
Removing Elements
Imagine you have this list:
tasks = ['email Ann', 'call Max', 'meet with classmates'] print(tasks)
You can also remove an item from the list by specifying its value. Here's how to do that.
tasks = ['email Ann', 'call Max', 'meet with classmates'] tasks.remove('call Max') print(tasks)
Now, the list is down to two items instead of three:
tasks[0]
reads'email Ann'
;tasks[1]
reads'meet with classmates'
.
Note
With the
remove()
method, you can only take out one item at a time.
Task
You've got this list:
numbers = [10, 12, 14, 16, 18, 20]
Your goal is to end up with:
numbers = [12, 14, 16]
Thanks for your feedback!
Imagine you have this list:
tasks = ['email Ann', 'call Max', 'meet with classmates'] print(tasks)
You can also remove an item from the list by specifying its value. Here's how to do that.
tasks = ['email Ann', 'call Max', 'meet with classmates'] tasks.remove('call Max') print(tasks)
Now, the list is down to two items instead of three:
tasks[0]
reads'email Ann'
;tasks[1]
reads'meet with classmates'
.
Note
With the
remove()
method, you can only take out one item at a time.
Task
You've got this list:
numbers = [10, 12, 14, 16, 18, 20]
Your goal is to end up with:
numbers = [12, 14, 16]