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 trialGregory Heard
1,975 PointsDictionary comparison challenge
Hi, this code works in my workspace pefectly fine. But in the code challenge it says it returns 1 when it should return 2.
Any help i greatly appreciated.
Thanks
def members (dictionary, keys):
common = 0
for keys in dictionary:
common += 1
return(common)
2 Answers
jcorum
71,830 PointsGregory, you need to compare the keys in one list with the keys in the other:
def members(my_dict, my_list):
count = 0
for key in my_dict:
if key in my_list:
count += 1
return count
Here we take each key in my_dict, and if it's also in my_list then we count it.
Gregory Heard
1,975 PointsHi,
Thanks for the speedy response. All makes sense now!