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 trialmessai mahdi
103 PointsPython 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
Kurt Maurer
16,725 PointsMessai,
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
6,727 PointsThe del keyword only takes indexes, the .remove() function, however, can take a name such as messy.remove(8)
Jonathan Borteij
866 PointsRemember, all index starts with number 0. In this case the number 8 are 2.
Try out with: del messy[2]