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!

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

Python Deletion from lists

i have to delete the 8 from the list with the Del keyword and it is not passing saying indexerror: list bla bla bla please help me

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

3 Answers


You're really close, remember you have to pass the index of the number you want to delete. In this case 8 is at index 2. Hope this helps!

Hasan Ahmad
Hasan Ahmad
6,726 Points

The del keyword only takes indexes, the .remove() function, however, can take a name such as messy.remove(8)

Jonathan Borteij
Jonathan Borteij
866 Points

Remember, all index starts with number 0. In this case the number 8 are 2.

Try out with: del messy[2]