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 trialBERNARD OWUSU
314 PointsKeeps saying task 1 not passing
Task one not passing error
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
states.remove(5)
states.remove(red)
5 Answers
Jimmy Smutek
Python Web Development Techdegree Student 6,629 PointsWhy do you have the last line, states.remove(red)
?
It's not needed, you've only been asked to remove the last item in the list. But, even if you were trying to remove "red" from the list you would trigger a NameError with your code as written.
Since you don't need to remove red I would suggest removing that line and seeing if your code passes.
Hope that helps!
BERNARD OWUSU
314 Pointsthe difficulty am having is in the second question which asked me to remove the second item on the list which is the red
Jimmy Smutek
Python Web Development Techdegree Student 6,629 PointsHey Bernard,
The instructions for the second part of the task state:
"OK, one more removal. See that second item in states? It's a list of colors and doesn't belong here. Can you get rid of it for me? Be sure to use .remove() again."
So you need to remove the entire list, but red
isn't a key, but rather is just a string inside of the list, so states.remove(red) isn't going to work.
One thing you might consider would be targeting items via their index in the main list. For example, in the states
variable -
states = [
'ACTIVE', # string, index 0 states[0]
['red', 'green', 'blue'], # index 1 / states[1]
'CANCELLED', # string, index 2 / states[2]
'FINISHED', # string, index 3 / states[3]
5, # int, index 4 / states[4]
]
You could target the last item by targeting the object directly, with states.remove(5)
, or via its index, with states.remove(states[4])
.
Does this help get you closer?
Luke Massetti
4,530 PointsHello,
This did not help me, it is not clear what you wrote in green i.e. index / states. (More confusing) Here is what I put: states.remove[('red', 'green', 'blue')]
Thank you.
Jimmy Smutek
Python Web Development Techdegree Student 6,629 PointsHi Luke,
The green text items are just comments supporting the explanation.
Index is the items position in the list. For example, the word ACTIVE is first in the list, so its index is 0.
states
is just the name of the variable that's been assigned to hold the list. Given the list above, states[0]
will return the string ACTIVE
, and states[1]
will return the list ['red', 'green', 'blue']
, etc.
Hope that clears things up.
jalil damian
1,452 Pointstanks that realy help