"""
Learning Goals:
 - Identify the keys and values in a dictionary
 - Use dictionaries when writing and reading code that uses pairs of data
 - Use for loops to iterate over the parts of an iterable value
"""

d = { "PA" : "Pittsburgh", "NY" : "New York City" }
d["WA"] = "Seattle"
d["NY"] = "Buffalo"
if "Pittsburgh" in d:
    d.pop("Pittsburgh")

###

wordList = [ "Hello", "World" ]
for word in wordList:
    print(word, "!")

###

d = { "bananas" : 4, "apples" : 1, "watermelon" : 10 }
for fruit in d:
    print("Key:", fruit)
    print("Value:", d[fruit])

###

foods = { "apples" : 5, "beets" : 2, "lemons" : 1 }
def countItems(foodCounts):
    total = 0
    for food in foodCounts:
        print(foodCounts[food], food)
        total = total + foodCounts[food]
    return total

###

studentList = [ "erhurst,CIT", "neerajsa,SCS",
                "cosorio,DC",  "dtoussai,CIT",
                "emaburi,CIT", "frankh,MCS",
                "ilu1,MCS" ]
def getCollegeCounts(students):
    d = { }
    for info in students:
        tokens = info.split(",")
        student = tokens[0]
        college = tokens[1]
        if college not in d:
            d[college] = 1
        else:
            d[college] = d[college] + 1
    return d

counts = getCollegeCounts(studentList)
print(counts)

###

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

print(mostPopularCollege(counts))

###

def createMultDict(n):
    outer = { }
    for x in range(1, n+1):
        inner = { }
        for y in range(1, n+1):
            inner[y] = x * y
        outer[x] = inner
    return outer

print(createMultDict(4))