Python Python Collections Dictionaries Teacher Stats

vikas Rai
vikas Rai
9,599 Points

I am getting error "Couldn't find 'most_courses'"

I am getting error "Couldn't find 'most_courses'" while method is already there.

teachers.py
# 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
MOD
Chris Freeman
Treehouse Moderator 55,471 Points

There 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.