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 trialvikas Rai
9,703 PointsI am getting error "Couldn't find 'most_courses'"
I am getting error "Couldn't find 'most_courses'" while method is already there.
# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
# 'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Each key will be a Teacher and the value will be a list of courses.
#
# Your code goes below here.
def most_courses (dict):
lis=[]
lisf=[]
tdict={}
#max_count=0
for x in dict:
var=dict[x]
#print(len(var))
if isinstance(var, list):
a
tdict[x]=len(var)
lis.extend(var)
else:
tdict[x]=1
print(tdict)
max_count=[]
i=0
for x in tdict:
if tdict[x]>i:
i=tdict[x]
max_count.append(x)
elif tdict[x]==i:
max_count.append(x)
return max_count
def num_teachers (dict):
return len(dict)
def num_courses(dict):
lis=[]
lisf=[]
for x in dict:
var=dict[x]
if isinstance(var,list):
lis.extend(var)
else: lis.append(var)
for x in lis:
if x not in lisf:
lisf.append(x)
return len(lisf)
def courses(dict):
lis=[]
lisf=[]
for x in dict:
var=dict[x]
if isinstance(var,list):
lis.extend(var)
else: lis.append(var)
for x in lis:
if x not in lisf:
lisf.append(x)
return lisf
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsThere is a line with just a. Since a
is not defined it is an error.
The function most_courses
should return the name of the teacher not the number of classes.