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

'builtin_function_or_method' not iterable

Hey guys,

Got a bit of code here that looks like this:

def members(dict, list):
  inc_item = []
  for item in list:
    if item in dict.keys:
      inc_item.append(item)

  return len(inc_item)

Inputs are a dictionary and a list of keys looking to return the number of keys in the list that are included in the dictionary. When I try to check it i get the following: argument of type 'builtin_function_or_method' is not iterable.

Is there something that I'm missing? Or is my code just dumb?

Thanks

2 Answers

I figured it out:

dropped the ".keys" on line 4 and it works.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

.keys is a method that's built into the dict type. Since it's a method, it has to be called, .keys(), and not just used directly like you were doing.

But, yes, you don't need the .keys() for this.