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) Dictionaries Membership

Shawndee Boyd
Shawndee Boyd
6,002 Points

Why doesn't this code work on the Membership Challenge within Python Collections?

def members{dict, keys}:
  return len(members.keys())

I've changed the format of your question to make the code clearer

3 Answers

David Bouchare
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

You'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
Sergio Niño
Full Stack JavaScript Techdegree Student 22,976 Points

i like those answers, without saying everything and that they will be right, is better with little hints, definitely I learned more.