Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python Data Types list.remove()

I'm confused

I'm confused

lists.py
states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
]

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

The list of items you're removing from is "states". So you will access it and perform the remove function on it. Then you provide that function with what you'd like to remove. See the following code:

states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
]

states.remove(5);
states.remove(['red', 'green', 'blue']);
Michael Chan
Michael Chan
15,252 Points

Hello Nathan,

Think of a list as a box that can contain many different types of objects: strings, lists, integers, and so on. What list_name.remove() does is you asking someone else to remove an item from that box. You know what item you'd like to remove from the box but the other person needs specific instructions on what that item looks like in order to remove it.

When we want to remove strings, which are the objects with single quote marks around them, you'll have to do states.remove('ACTIVE') or states.remove('CANCELLED').

When we want to remove integers, we'll do states.remove(5).

One last thing, the .remove() method takes only one argument at a time, which means you can only ask it to remove one item at a time.

Hopefully this helps with your question!