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 trialMichael Spinks
1,150 PointsPlease can you provide some clarity of the dictionary of teachers?
I have tried passing the dictionary of teachers and iterating through the items to append to a list. However this breaks task 1. I am returning the list of courses. Not sure where I am going wrong.
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
def most_classes(dicts):
my_dict = {}
for i, j in dicts.items():
#print i
my_dict[i] = i
# print my_dict[i]
count = 0
# add i as the value in our own dictionary
for k in j:
# print k
count += 1
# print count
my_dict[i] = count
return max(my_dict, key=my_dict.get)
def num_teachers(teachers):
max_count = 0
max_count = len (teachers)
return max_count
def stats(dicts):
list_of_lists = []
stat_list = []
for i, j in dicts.items():
count = 0
for k in j:
count += 1
stat_list = [i,count]
list_of_lists.append (stat_list)
return list_of_lists
def courses(teachers):
course_list = []
for i, j in teachers.items():
for k in j:
print k
course_list.append(k)
return course_list
2 Answers
Keerthi Suria Kumar Arumugam
4,585 PointsYour algorithm looks fine. You are missing a parenthesis in the print statement in your last function, if you intended to print it. Else, comment that line out. Your code worked in my console.
For your reference, this is the code that I ran.
# The dictionary will be something like:
# {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Often, it's a good idea to hold onto a max_count variable.
# Update it when you find a teacher with more classes than
# the current count. Better hold onto the teacher name somewhere
# too!
#
# Your code goes below here.
def most_classes(dicts):
my_dict = {}
for i, j in dicts.items():
#print i
my_dict[i] = i
# print my_dict[i]
count = 0
# add i as the value in our own dictionary
for k in j:
# print k
count += 1
# print count
my_dict[i] = count
return max(my_dict, key=my_dict.get)
def num_teachers(teachers):
max_count = len (teachers)
return max_count
def stats(dicts):
list_of_lists = []
stat_list = []
for i, j in dicts.items():
count = 0
for k in j:
count += 1
stat_list = [i,count]
list_of_lists.append (stat_list)
return list_of_lists
def courses(teachers):
course_list = []
for i, j in teachers.items():
for k in j:
print(k)
course_list.append(k)
return course_list
my_dict = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
'Kenneth Love': ['Python Basics', 'Python Collections']}
print(most_classes(my_dict))
print(num_teachers(my_dict))
print(stats(my_dict))
print(courses(my_dict))
Michael Spinks
1,150 PointsThanks for your help. All done now.