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 trialShawndee Boyd
6,002 PointsWhy doesn't this code work on the Membership Challenge within Python Collections?
def members{dict, keys}:
return len(members.keys())
3 Answers
David Bouchare
9,224 Points+1 with what Ryan said above. Also, you're using {} instead of () when writing your function. It should be:
def members(dict, keys):
#rest of the code
Also "dict" is a reserved keyword to manipulate dictionaries, if I am not mistaken.
Some pseudo code that could help you:
def members(dict1, keys):
#set a counter to 0
count = 0
for e in keys:
#check if that element is in the dictionary
#increment the counter
return count
Ryan Carson
23,287 PointsYou're supposed to be counting the unique keys in the dictionary. I would suggest keeping track of how many unique keys there are in the dictionary, by looping through the dictionary. Good luck!
I had to use a for
loop and an if
statement.
Sergio Niño
Full Stack JavaScript Techdegree Student 22,976 Pointsi like those answers, without saying everything and that they will be right, is better with little hints, definitely I learned more.
Ryan Carson
23,287 PointsRyan Carson
23,287 PointsI've changed the format of your question to make the code clearer