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 trialBrent Liang
Courses Plus Student 2,944 PointsTry Again?
What's wrong with this code?
# You can check for dictionary membership using the
# "key in dict" syntax from lists.
### Example
# my_dict = {'apples': 1, 'bananas': 2, 'coconuts': 3}
# my_list = ['apples', 'coconuts', 'grapes', 'strawberries']
# members(my_dict, my_list) => 2
def members ():
my_dict = {'Shoes': 1, 'Clothes': 2, 'Caps': 3}
my_list = ["Clothes", "Caps"]
z = 0
for item in my_list:
for key in my_dict:
if item == key:
z += 1
else:
continue
return z
Brent Liang
Courses Plus Student 2,944 PointsThanks Kevin. I will specify the question/prompt next time. Much appreciation for your feedback.
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! The problem lies in following the instructions of the challenge. The method is supposed to have two parameters. One takes a dictionary and the other takes a list of keys. Treehouse is going to be sending those to your code and you don't get to decide what they're sending.
In short, you need to remove the definitions of my_dict and my_list and set them as parameters in your method definition. When I do that, your code passes the challenge.
Hope this helps!
Brent Liang
Courses Plus Student 2,944 PointsHey Jen, yes it works!! Thank you so much for the answer, it's amazing.
Kevin Elliott
15,653 PointsKevin Elliott
15,653 PointsRather than just ask for what is wrong with your code, you should elaborate for everyone what your problem seems to be. In other words, just asking for what is wrong with your code will get you some kind of answer, but it might not be the one you want. I would suggest you include any compiler or runtime errors, and/or explain any issues that are occurring such as values that are coming out wrong after the loops run, etc.