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 trialNicholas Tapps
426 PointsI keep getting a SyntaxError because I don't know what, CANCELLED and FINISHED mean.
Based on everything I've learned thus far, the name of the variable (or in this case, the list) should be, "states", but whenever I use the function, "states.remove()" I get a SyntaxError; I believe this is either because I don't know exactly what all the additional information is doing there and what exactly is in the list.
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
2 Answers
AJ Salmon
5,675 PointsHi Nicholas,
You're right that the variable name is states
! And in this case it is a list. However, I think I might see a problem; there doesn't appear to be a closing bracket on your list. It should come after 5, and look like this -
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
This particular list contains multiple things. Three strings, an integer, and another list comprised of three strings. When using .remove()
, the item you wish to remove needs to go inside the parentheses after remove, in its entirety, so if you're directly removing a string, you must include the quotation marks around the outside of it, and same goes for any other python class type. Ex:
states.remove('FINISHED')
states.remove(5)
states.remove(['red', 'green', 'blue'])
The items inside a list should not interfere with how that list is processed, so the strings 'CANCELLED'
and 'FINISHED'
are just that; strings! Any removing that you do should be written after the list is closed, and I like to keep a space in between any variables and actions, just to be safe. Hopefully this clears it up a little bit, if you have any more questions feel free to ask. Happy coding :)
Luke Strama
6,928 PointsThe list of 'states' contain items and none of those items do anything specific except take a spot in the list. The objective is to remove the items that don't fit. The way to do this is to use the remove() function and reference the 'states' list when doing so (hint: it involves dot notation and you can only remove 1 item at a time by typing it in between the '()').