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 trialmarinmirosevic
3,279 Pointslist.remove
states = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5, ] states.remove(['red', 'green', 'blue'])
this doesnt work i tried on unix it works - what is the problem?
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
6 Answers
Jennifer Nordell
Treehouse TeacherHi there tanmay sharma! To remove the items from a list the code needs to be outside the definition of the states
array. And we do this like so:
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
states.remove(5)
states.remove(['red', 'green', 'blue'])
The first states.remove
will remove the 5. 5 is not a string, nor is it part of an array inside of an array, so only the 5 is needed inside the parentheses. The second states.remove
line needs the brackets inside the parentheses as we're removing an array from inside an array. Hope this helps!
marinmirosevic
3,279 Pointsagain
states = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5, ] states.remove(['red', 'green', 'blue'])
henry jefferson
2,136 Pointstry this:
states = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5, ]
states.remove(['red', 'green', 'blue'])
print (states)
henry jefferson
2,136 PointsI think you have to perform states.remove() on a separate line. Also, it's worth noting that workspaces can be buggy. Sometimes try saving and reloading the page.
marinmirosevic
3,279 Pointsthank Henrys. what i noticed on that page where script is to be writtten GET HELP doesnt work also
tanmay sharma
267 Pointshow to remove 5from that list
tanmay sharma
267 Pointstanmay sharma
267 Points@Jennifer Nordell thanks for the help