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

Lists redux

Hi I'm wondering why in this code challenge I could not get the 2nd part (remove string, list and boolean values) working any other way than -

for t in the_list: if type(t) is str: the_list.remove(t) elif type(t) is list: the_list.remove(t) for t in the_list: if type(t) is bool: the_list.remove(t)

I tried using -

for t in the_list: if type(t) is str or type(t) is list or type(t) is bool: the_list.remove(t)

And then -

for t in the_list: if type(t) is str: the_list.remove(t) elif type(t) is list: the_list.remove(t)
elif type(t) is bool: the_list.remove(t)

But no joy! Can anyone help?

3 Answers

here man, its much simplier to do this:

the_list.remove("a")

del the_list[3]

the_list.remove([1, 2, 3])

this same question was asked before somehow with a diferent problem https://teamtreehouse.com/forum/python-collection-challenge-task-2-out-of-3

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Generally not a great idea to check types with type(). Better to do isinstance(variable, type). But, like Abdul hamid Achik Lopez pointed out, you don't need to do type checking on this at all.

Thanks guys