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 trialYasser Shaaf
UX Design Techdegree Student 13,865 Pointsmessy = [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
Treehouse Moderator 68,441 Pointsdel
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]
Yasser Shaaf
UX Design Techdegree Student 13,865 PointsThank you so much , I really struggle with python , have you experienced this struggle ?
Chris Freeman
Treehouse Moderator 68,441 PointsEarly 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!
mohammed alali
3,415 Pointsmohammed alali
3,415 Pointswhy its give Oops! It looks like Task 1 is no longer passing.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsMohammed, "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.
mohammed alali
3,415 Pointsmohammed alali
3,415 Pointsit's still give task one is no longer passing this code is correct or not :
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsMohammed, after
del messy[2]
is executed there is no longer an "8
" in the list to remove. This causes theremove()
to raise an error.Additionally, task 2 in the challenge asks to use
del
instead ofremove
.