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 trialDustin Vandehey
969 Points.remove function is not functioning
for some reason I am not getting .remove to work correctly. Maybe I am overthinking it. It seems to be asking to remove the 5. Am a bit confused. Thanks
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
states.remove[5]
1 Answer
Gavin Ralston
28,770 Pointslist.remove(something)
You're using index notation, not using parenthesis to pass in a parameter. (It's a method)
You'd use the list (or array, or index) notation directly on the list, like...this way to remove an item:
list = ['a', 'b', 'c']
del list[0]
# list would now be ['b', 'c']
Dustin Vandehey
969 PointsDustin Vandehey
969 PointsThanks so much. I ended up figuring it out. I think I got confused from the video. So if you are removing just one thing, it would just require parenthesis? If multiple items, then [] within ()? Correct? Thanks again for the prompt response.
Gavin Ralston
28,770 PointsGavin Ralston
28,770 Pointsremove() is the method you call on any list, and you pass in a value you want to remove. So I could call:
list.remove('a')
...and it'd find the first occurrence and remove it. Not all the elements with 'a', but the first one.
When you use brackets on a list, you're not calling a method of a list, you're instead going directly to the location in that list and examining/using whatever is inside of it:
So the methods are what lists know how to do, like "remove(a_value_you_provide)" and index notations are just addresses you point to directly to access whatever is stored there.