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 trialBennett Golden
1,462 Pointshaving trouble removing str, boolean and list from the_list
I'm supposed to use remove or del to get rid of the str, boolean and list from the_list, but I can't figure it out. I'm very new to Python and I'm having a tough time making sense of this. This is the best code I've come up with, but it still doesn't work.
I tried: for item in the_list: while True: try: del the_list() except: break
but it really didn't like that one.
can someone point me in the right direction, please?
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
first = the_list.pop(3)
the_list.insert(0,first)
# Your code goes below here
for str in the_list:
while True:
try:
the_list.remove(str)
except:
break
for bool in the_list:
while True:
try:
the_list.remove(bool)
except:
break
for list in the_list:
while True:
try:
the_list.remove(list)
except:
break
2 Answers
Ken Alger
Treehouse TeacherBennett;
Welcome to Treehouse!
You can greatly simplify your efforts on this one, let's take a look:
Task 2
Use .remove() and/or del to remove the string, boolean, and list members of the_list.
Removing the string can be accomplished with:
the_list.remove("a")
Removing the boolean...
del the_list[3]
Removing the list members...
the_list.remove([1, 2, 3])
Hope that helps and post back if you have additional questions.
Happy coding,
Ken
Bennett Golden
1,462 PointsOk, wow! That was so much simpler than I was thinking it was... Thanks a lot, Ken. Don't know why I make things so hard for myself sometimes.
Ken Alger
Treehouse TeacherNo worries. It is part of the learning process and can lead to some "ah-ha" moments when you work up a reasonable approach to a problem only to discover that there is a built in function to do a task.
Great job sticking with it!
Happy coding,
Ken