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

Course Content

Python Data Structures

Deleting ElementsDeleting Elements

Imagine you have a to-do list:

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:

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.

Everything was clear?

Section 1. Chapter 9
toggle bottom row
course content

Course Content

Python Data Structures

Deleting ElementsDeleting Elements

Imagine you have a to-do list:

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:

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.

Everything was clear?

Section 1. Chapter 9
toggle bottom row
some-alt