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 trialDan Andresen
Courses Plus Student 636 PointsIndentation error on dictionaries code challenge.
Hi, there.
I keep getting this indentation error on my return command and I'm not sure why. If I try to move it I still get "Bummer! Try again." it is only in this spot that I get the indentation error. Any help would be greatly appreciated.
Thanks Dan
# 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
my_dict = {'apples': 1, 'bananas': 2, 'cocnuts': 3}
my_list = ['apples', 'coconuts', 'grapes', 'strawberries']
def members(my_dict, my_list):
for item in my_list:
if item in my_dict:
my_dict[item] += 1
else:
my_dict[item] = 1
return my_dict
1 Answer
Kenneth Love
Treehouse Guest TeacherYour if
and your else
should line up. Also, your for
and return
.
Dan Andresen
Courses Plus Student 636 PointsDan Andresen
Courses Plus Student 636 PointsHi, First I'd like to say thanks, I'm loving the tutorials and treehouse has been the perfect platform to be able to get my feet wet in programming! :)
I lined everything up and made it a little less complicated and it worked!
Thanks for the reply and the tutorials! Dan