Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Deleting Elements | List
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set
5. For deleting

bookDeleting Elements

Imagine you have a to-do list:

12
tasks = ['email Tom', 'call Max', 'meet with sister'] print(tasks)
copy

This list contains 3 items.

Let's say you've finished the first task on this list; meaning, you've already sent an email to Tom. To cross that task off the list, you'd write:

123
tasks = ['email Tom', 'call Max', 'meet with sister'] del tasks[0] print(tasks)
copy

Now, the list is down to two tasks:

  • tasks[0] reads 'call Max';
  • tasks[1] reads 'meet with sister'.

You can remove any item from the list by using its index number.

Note

Curious about the syntax of del?

  • The statement starts with the keyword del;
  • Next, you typically identify the list item with its index like tasks[index].

Time to give it a shot!

Task

Here's your list:

groups = ['The Beatles', 'The Band', 'The Clash', 'The Dillards', 'The Mamas and the Papas', 'The Kingston Trio']

Your task is to remove the following bands from the list using positive indexing only: 'The Beatles' and 'The Mamas and the Papas'.

Stuck on which indexes to use for removal? Check out the hints.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 9
toggle bottom row

bookDeleting Elements

Imagine you have a to-do list:

12
tasks = ['email Tom', 'call Max', 'meet with sister'] print(tasks)
copy

This list contains 3 items.

Let's say you've finished the first task on this list; meaning, you've already sent an email to Tom. To cross that task off the list, you'd write:

123
tasks = ['email Tom', 'call Max', 'meet with sister'] del tasks[0] print(tasks)
copy

Now, the list is down to two tasks:

  • tasks[0] reads 'call Max';
  • tasks[1] reads 'meet with sister'.

You can remove any item from the list by using its index number.

Note

Curious about the syntax of del?

  • The statement starts with the keyword del;
  • Next, you typically identify the list item with its index like tasks[index].

Time to give it a shot!

Task

Here's your list:

groups = ['The Beatles', 'The Band', 'The Clash', 'The Dillards', 'The Mamas and the Papas', 'The Kingston Trio']

Your task is to remove the following bands from the list using positive indexing only: 'The Beatles' and 'The Mamas and the Papas'.

Stuck on which indexes to use for removal? Check out the hints.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 9
toggle bottom row

bookDeleting Elements

Imagine you have a to-do list:

12
tasks = ['email Tom', 'call Max', 'meet with sister'] print(tasks)
copy

This list contains 3 items.

Let's say you've finished the first task on this list; meaning, you've already sent an email to Tom. To cross that task off the list, you'd write:

123
tasks = ['email Tom', 'call Max', 'meet with sister'] del tasks[0] print(tasks)
copy

Now, the list is down to two tasks:

  • tasks[0] reads 'call Max';
  • tasks[1] reads 'meet with sister'.

You can remove any item from the list by using its index number.

Note

Curious about the syntax of del?

  • The statement starts with the keyword del;
  • Next, you typically identify the list item with its index like tasks[index].

Time to give it a shot!

Task

Here's your list:

groups = ['The Beatles', 'The Band', 'The Clash', 'The Dillards', 'The Mamas and the Papas', 'The Kingston Trio']

Your task is to remove the following bands from the list using positive indexing only: 'The Beatles' and 'The Mamas and the Papas'.

Stuck on which indexes to use for removal? Check out the hints.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Imagine you have a to-do list:

12
tasks = ['email Tom', 'call Max', 'meet with sister'] print(tasks)
copy

This list contains 3 items.

Let's say you've finished the first task on this list; meaning, you've already sent an email to Tom. To cross that task off the list, you'd write:

123
tasks = ['email Tom', 'call Max', 'meet with sister'] del tasks[0] print(tasks)
copy

Now, the list is down to two tasks:

  • tasks[0] reads 'call Max';
  • tasks[1] reads 'meet with sister'.

You can remove any item from the list by using its index number.

Note

Curious about the syntax of del?

  • The statement starts with the keyword del;
  • Next, you typically identify the list item with its index like tasks[index].

Time to give it a shot!

Task

Here's your list:

groups = ['The Beatles', 'The Band', 'The Clash', 'The Dillards', 'The Mamas and the Papas', 'The Kingston Trio']

Your task is to remove the following bands from the list using positive indexing only: 'The Beatles' and 'The Mamas and the Papas'.

Stuck on which indexes to use for removal? Check out the hints.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 9
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt