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

i dont know how to delete more than on element from the string

how do you delete more than one element from a string? (using del) i need to remove all the even numbers

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

2 Answers

I wasn't able to find a 'simple' way with using just the del statement, but you could do something like the following: (Note: my Python syntax is a bit rusty)

for index in messy:
    if index % 2 == 0:
        del messy[index]

Syntax is probably off, but that should give you the gist of it.

Edit: Silly me, I checked the challenge after giving my answer and realized they are only asking you to do one at a time. :p So no need to over complicate it.


No problem, turns out they only were asking you to do one at a time though in the challenge. Sorry I over complicated it. :D