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()

How do you use the remove function without affecting previous removals? I am having issues with the removal exercise.

Below is what I'm using. However, it seems that the first removal is no longer valid after I input the second (from what the exercise is telling me).

states.remove(5) states.remove([red, green, blue])

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

2 Answers

andren
andren
28,558 Points

The first removal is fine, the reason why task 1 no longer passes after you enter your code for task 2 is that your code has syntax errors in it, which invalidates all of your code as far as the code checker is concerned.

There are two errors in your code:

  1. When you call a method like remove you need to place parenthesis after it, and pass the argument within those parenthesis.
  2. The words red, green and blue are strings so you need to wrap them in quote marks.

Like this:

states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
]
states.remove(5)
states.remove(['red', 'green', 'blue']) # Added () around argument and quotes around strings.

Gotcha. Thank you!