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 Collections (Retired) Lists Redux Manipulating Lists

Dhruv Ghulati
Dhruv Ghulati
1,582 Points

How to delete boolean, string and list within the_list - dont know conditional for these attributes

Not sure how to do this. Can I call delete on multiple index values by the way e.g. del the_list(0,4,5) to delete 3 index values? Here in my code I try on separate lines, and it says 'Ooops, looks like code from part one is not working'

lists.py
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here
the_list.insert(0,the_list.pop(3))
del the_list[1]
del the_list[5]
del the_list[6]

2 Answers

You'll have five items in your list after the del the_list[1] line hence del the_list[5] will throw and index out of range error because you only have five items left. Remember that index starts from 0 therefore for 5 items you should be deleting an item with an index <= [5-1] . And i'm not sure you can delete multiple items from a list with a single call due to the fact that the size of the list will shrink when any item is removed and therefore.

Dhruv Ghulati
Dhruv Ghulati
1,582 Points

Thanks a lot - makes total sense. By making the del option anything less than a value rather than the value itself I see how it would solve it. Thanks calistus!