"""
Learning Goals:
 - Read and write code using 1D and 2D lists
 - Use list methods to change lists without variable assignment
"""

lst = [23, 1, 43, 56, 20, 9]
total = 0
for i in range(len(lst)):
    total = total + lst[i]
print(total)

###

def findName(sentence, name):
    words = sentence.split(" ")
    for i in range(len(words)):
        if words[i] == name:
            return True
    return False

print(findName("Ask Tom to phone Nina", "Kelly"))
# words holds ["Ask", "Tom", "to", "phone", "Nina"]

###

lst = ["a", "b", 1, 2]

print(lst[1]) # Q1

s = ""
for i in range(len(lst)):
    s = s + str(lst[i])
print(s) # Q2

###

lst = [23, 1, 43, 56, 20, 9]

def getMax(lst):
    biggest = lst[0]
    for i in range(len(lst)):
        elem = lst[i]
        if elem > biggest:
            biggest = elem
    return biggest

###

cities = [ ["Pittsburgh", "Allegheny", 302407],
           ["Philadelphia", "Philadelphia", 1584981],
           ["Allentown", "Lehigh", 123838],
           ["Erie", "Erie", 97639],
           ["Scranton", "Lackawanna", 77182] ]

def getCounty(cityData, name):
    for i in range(len(cities)):
        lst = cities[i]
        if lst[0] == name:
            return lst[1]

print(getCounty(cities, "Allentown"))

###

gameBoard = [ ["X", " ", "O"],
              [" ", "X", " "],
              [" ", " ", "O"] ]

for row in range(len(gameBoard)):
    tmp = ""
    for col in range(len(gameBoard[row])):
        mark = gameBoard[row][col]
        tmp = tmp + mark
    print(tmp)

###

def getFactors(n):
    factors = []
    for num in range(1, n+1):
        if n % num == 0:
            factors.append(num)
            print(factors)
    return factors

print(getFactors(42))