"""
Learning Goals:
 - Identify the keys and values in a dictionary
 - Use dictionaries when writing and reading code
"""

d = { "apples" : 5, "beets" : 2, "lemons" : 1 }
for k in d:
    print("Key:", k)
    print("Value:", d[k])

####

def countItems(foodCounts):
    totalCount = 0
    for k in foodCounts:
         print(foodCounts[k], k)
         totalCount = totalCount + foodCounts[k]
    return totalCount

d = { "apples" : 5, "beets" : 2, "lemons" : 1 }
print(countItems(d))

####

def countByCollege(studentList):
    d = { }
    for s in studentList:
        comma = s.find(",")
        name = s[:comma]
        college = s[comma+1:]
        if college not in d:
            d[college] = 1
        else:
            d[college] = d[college] + 1
        print(d)
    return d

def mostPopularCollege(d):
    bestCollege = None
    bestCount = 0
    for college in d:
        if d[college] > bestCount:
            bestCollege = college
            bestCount = d[college]
    return bestCollege

studentList = [ "erhurst,CIT", "neerajsa,SCS", "cosorio,DC", "dtoussai,CIT", "emaburi,CIT", "frankh,MCS", "ilu1,MCS" ]
tmp = countByCollege(studentList)
print(mostPopularCollege(tmp))