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 cleanup

Francisco Navarro
Francisco Navarro
225 Points

The challenge states to use del to delete the 8 from messy, but the only the del messy[2] is getting a 'well done', why?

Oh no! I have another messy list. This one has some even numbers in it and I want it to only have odd numbers. Use del to delete the 8 from messy.

Per the first secition of the task, the correct answer is del messy[2]. Shouldn't it be messy[8]?

The next task says: And, finally, we need to remove that 2. Can you delete it with del, too? Thanks! But the del messy [2] was deleted from the previous task. Neither del messy[2] nor del messy[8] works on the second task.

I'm not sure what I am missing? should task 1 be: del messy[8] and task 2 be: del messy[2]?

lists.py
messy = [5, 2, 8, 1, 3]
del messy[8]

4 Answers

Hi,

The del keyword is looking for an index, so del messy[2] will delete the item at index 2, which is the integer 8. To remove the 8 in the way you are trying, you would do it with the .remove method: messy.remove(8)

step one should look like this. Remember that integer 5 = index 0, integer 2 = index 1, integer 8 = index 2, integer 1 = index 3, and integer 3 = index 4.

messy = [5, 2, 8, 1, 3]
del messy[2]

step two should look like this. Remembering again that the del is looking for an index, del messy [2] will hit the integer 8. In this step they want us to remove the integer "2" so we use the code "del mess [1] as the 2 is at index 1.

messy = [5, 2, 8, 1, 3]
del messy[2]
del messy[1]

Nothing works on this thread

In Python Basics Kevin Love claims that 54 years old is time to retire. Were he to make comments about the kilogram integer of fat women or the float height of black men I am certain that he would be pilloried with abuse. As his demographic is not on the downward trajectory - Kevin might wish to revise his example.