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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![charles mills](https://secure.gravatar.com/avatar/20b04bf51bd5e81423785489abccc44e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
charles mills
1,856 PointsHow can I make a remove Method that goes through my list?
I would like to make a remove method
something like
def type_check :
if the element in the list is type [String, boolean]
remove from list.
I took a look around at the documentation but I couldn't really get anywhere. I was attempting make a method to try to solve stage 2 of list redux.
If you can point me to some pseudo code and some docs maybe I can skratch up a question that the oracles at StackOverflow can look down on through their glasses, it they aren't fogged up by hot air.
![charles mills](https://secure.gravatar.com/avatar/20b04bf51bd5e81423785489abccc44e?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
charles mills
1,856 Pointsyes sir it is tied to stage 2 of the list redux. The task is to find the boolean, the string and one other thing and delete it from the list . It sounds like they want a method right?
I feel that many of these questions are somewhat vague and lots of unexpected things can happen, like asking bakers to show up for a creampie casting couch....
2 Answers
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsHere is one way to do it:
In [40]: def removeitems(list):
....: remove_types = [str, bool]
....: result = []
....: for item in list:
....: if not type(item) in remove_types:
....: result.append(item)
....: return result
....:
In [41]: removeitems(['s', 1, True, 4, 's'])
Out[41]: [1, 4]
If you want edit the list in place, then assign result to list:
In [50]: def removeitems2(list):
remove_types = [str, bool]
result = []
for count, item in enumerate(list):
if not type(item) in remove_types:
result.append(item)
list[:] = result
....:
In [51]: list = ['s', 1, True, 4, 's']
In [52]: removeitems2(list)
In [53]: list
Out[53]: [1, 4]
![Kenneth Love](https://uploads.teamtreehouse.com/production/profile-photos/710512/micro_TeacherShoot-Kenneth.jpg)
Kenneth Love
Treehouse Guest TeacherIt's not a good idea to change a list while you're going through it. To solve the challenge, you don't need to write code like this, either.
![Matthew Proudman](https://secure.gravatar.com/avatar/43e0ab453b650142e267877eb0577760?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Matthew Proudman
11,879 Pointsokay Kenneth sorry it on my phone late at night deleted the post
Stephen Bone
12,359 PointsStephen Bone
12,359 PointsHi Charles
Sorry just trying to understand further is this tied to a stage (as I can't seem to find it) or are you just trying to figure out some code?
Thanks Stephen