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

Why is this task giving me a SyntaxError whenever I try to remove the last item from the list?

I am getting a Syntax error whenever I try to remove the "5" from the list in the task on the website, however I wrote my own code in the workspaces and I have been able to remove whatever I please from the list. Here is my code that is working:

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

^

in workspaces, this is doing exactly what I'm being ask to do in the task.

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

2 Answers

andren
andren
28,558 Points

Because you have (accidentally I assume) removed the ] bracket that marks the end of the states array. If you add it back like this:

states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
] # <- This was missing from your code
states.remove(5)

Then your code will work.

Thx man