Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
19,526 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,307 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,307 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