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

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

stuck again.

states.remove (['red', 'green', 'blue'])

Whats wrong now?

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

2 Answers

Josh Keenan
Josh Keenan
20,315 Points

Hey Jamie, it's a weird challenge isn't it?

Here's my solution to the challenge, instead of explicitly typing the list you want to remove, I just found the index in the list and removed it that way.

states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
]

states.remove(5)
states.remove(states[1])
Ryan Ruscett
Ryan Ruscett
23,309 Points

This is also a clean way to do it. In a production setting, this would be more accurate. It ensures the list item itself is removed, and not just the values from the list, which in some situations could leave an empty list behind. Which we may or may not want.

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

thanks Josh. much appreciated

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

Thanks dude. Don't really understand your way but thanks anyway

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hola,

No worries, you are right and definitely on the right track. The only problem is the space.

states.remove (['red', 'green', 'blue']) < ----- REMOVE the space between removes and the ().

LIKE THIS
states.remove(['red', 'green', 'blue'])

Aside from that, you got it!

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

thanks Ryan. Appreciate your time