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

how to

pretty sure i got it right

lists.py
messy = [5, 2, 8, 1, 3]
del messy[2,8]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

The 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
Stuart Wright
41,118 Points

The 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.