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

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

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

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.

thanks Josh. much appreciated

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

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!

thanks Ryan. Appreciate your time