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 trialchristian craigen
159 Pointshow to
pretty sure i got it right
messy = [5, 2, 8, 1, 3]
del messy[2,8]
2 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsThe precise error you are getting is
>>> del messy[2,8]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers or slices, not tuple
While using a slice such as messy[1:3]
should work, the challenge is looking for two separate statements to delete the two even numbers. Remember, the numbers used in the del
statement are the indexes of the items, not the items themselves.
Post back if you need more help
Stuart Wright
41,120 PointsThe first thing to note is that you should use two lines to delete two elements:
del messy[x]
del messy[y]
Where x and y are integers which represent the index of the element you want to delete, not the value. I'll leave you to fill in the correct values for x and y, but let me know if you need any more help.