""" Week6-1 Notes """

# make a dictionary mapping strings to integers
d = { "apples" : 4, "pears" : 5 }
print("Apples:", d["apples"]) # the value paired with this key

d["pears"] = d["pears"] + 1 # updates the value
print("Pears:", d["pears"])


d["banana"] = 7 # adds a new key-value pair
print("Banana:", d["banana"])

d.pop("pears") # destructively removes
print("Dictionary now: ", d)

print("apples" in d) # True
print("kiwis" in d) # False

print("-----------------------")

###

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

print("-----------------------")

###

d = { "a" : 5, "b" : 7, "c" : 3}
for k in d:
    print("Key:", k, "Value:", d[k])

print("-----------------------")


###

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

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

print("-----------------------")

###

def countByCollege(studentLst):
    collegeDict = { }
    for pair in studentLst:
        name = pair[0]
        college = pair[1]
        if college not in collegeDict:
            collegeDict[college] = 0
        collegeDict[college] += 1
    return collegeDict


students = [ ["erhurst" ,"CIT"], ["neerajsa","SCS"], ["cosorio","DC"], ["dtoussai", "CIT"]]

print("Counting by college: ", countByCollege(students))

print("-----------------------")

###

# Didn't get to these in lecture - make sure to review on your own!

def mostPopularCollege(collegeDict):
    best = None
    bestScore = -1
    for college in collegeDict:
        if collegeDict[college] > bestScore:
            bestScore = collegeDict[college]
            best = college
    return best

print("Most popular college: ", mostPopularCollege(countByCollege(students)))

print("-----------------------")

###

def createMultDict(n):
    d = { }
    for x in range(1, n+1):
        innerD = { }
        for y in range(1, n+1):
            innerD[y] = x * y
        d[x] = innerD
    return d
m = createMultDict(4)
print("Multiplication table: ", m)
print("Two x three: ", m[2][3]) # 6


print("-----------------------")