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

I am not sure what this is asking me to do.

I know it wants me to remove the number 5 and 'clean up' this code but originally they're aren't five anything. I put five colors in. Should I put five states in? I am at I loss.

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

3 Answers

Hi Frank,

I just viewed the challenge and gave it a shot. You're right that its kinda confusing but you are over thinking it. The first step is to just remove the element '5' ie the last element. The second step is to remove the array of colors. You do not have to separate each type of data into their own array. I passed the challenge doing the following:

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

#completing step 1:
states.remove(5) 

#completing step 2:
states.remove(['red', 'green', 'blue'])

I hope that helps!

First off, don't edit the predefined code structure.

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

this should still read as it does.

second: https://docs.python.org/3/tutorial/datastructures.html

list.remove(x)
    Remove the first item from the list whose value is x. It is an error if there is no such item.
  • Python is a very popular language, because of that there is a bunch of documentation at your disposal.
  • Python is an interpreted languange and due to the nature of how the code is run, you also have access to a python interpreter which can help you extrapolate any issue you may have.

So to remove an item, you can use the value or the index.

states.remove(states[-1]) 
# which is the same as 
states.remove(5)
# the second challenge asks you to remove the list of colors from the states list
states.remove(states[1])
# again this is the same as
states.remove(['red','green','blue'])

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

its giving me 'name states not defined'

I'm not sure I understand what you are doing.

If you are entering your code as you wrote on that line, it is because you are declaring the states.remove command inside the array. The command must be type outside the array and after the array has been declared.

See my previous answer for this.