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

messy = [5, 2, 8, 1, 3] del = (8) what it is incorrect

messy = [5, 2, 8, 1, 3] del = (8) what it is incorrect

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

del is a built-in function to delete an object directly

messy = [5, 2, 8, 1, 3]
# delete item at index 2 from messy
del messy[2]

There is a list method .remove() that removes a item from a list:

>>> messy = [5, 2, 8, 1, 3]
>>> messy.remove(8)
>>> messy
[5, 2, 1, 3]

why its give Oops! It looks like Task 1 is no longer passing.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Mohammed, "Task 1 no longer passing" usually means mans a syntax error was introduced.

Don't include the ">>>" in your submitted code. It is output from the interactive Python shell.

it's still give task one is no longer passing this code is correct or not :

del messy[2]
messy.remove(8)
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Mohammed, after del messy[2] is executed there is no longer an "8" in the list to remove. This causes the remove() to raise an error.

Additionally, task 2 in the challenge asks to use del instead of remove.

Thank you so much , I really struggle with python , have you experienced this struggle ?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Early on, there are a lot of idioms to absorb, but keep at it. It doesn't take long to develop a good base understanding of the language which will allow you to work on more advanced topics soon.

One aspect to keep in mind is "everything in Python is an object". Soon you will start to see each object and how it's methods work to modify the object. The more you work with string, lists, dictionaries, the more the object viewpoint makes sense. Then you'll be ready for functions and classes! Keep at it! You'll get it!