Problem 1 --------- (a) 4 (b) "lastawath" (c) [3, 4, 5, 5, 6, 7] (d) ['02', '12', '22', '32', '42'] (e) ['This', 'list', 'with', 'few', 'nets', 'of'] (f) [['ne', 'd'], ['nesting']] (g) [['This', ['is', 'a']], 'a', ['list', 'with'], 'b', ['nets', 'of'], 'c'] (h) [10, 'nested', 20, ['few', [['dish']]], 30, 'nesting'] (i) [['This', ['is', 'a']], 'nested', ['list', 'with'], ['nets', 'of'], 'nesting'] (j) [0, 1, 2, 3, 4, 5] Problem 2 --------- (a) [3, 5, 7, 8] 10 [20, 30, 100, 102, 111] [20, 30] 100 [102, 111] [] 20 [30] [] 30 [] 7 6 (b) he ed is n op to he ed Problem 3 --------- (a) def computeLengths(L): answer = [] for x in L: if type(x) == str: # Append a length to answer answer.append(len(x)) else: # x is a list of strings and so we need to append a # list of lengths to answer answer.append([len(y) for y in x]) return answer (b) def removeNonPalindromes(L): answer = [] for x in L: # if length of x is odd if len(x) % 2 == 1: # assign to y the second half of x, exluding the # middle character y = x[len(x)//2+1:] # else if the length of x is even else: # assign to y the second half of x y = x[len(x)//2:] # compare the first half of x with y, reversed if x[:len(x)//2] == y[::-1]: answer.append(x) return answer Problem 4 --------- (a) def computeQuantities(pA, pB): L = [[x, (125-7*x)//11] for x in range(125//7)] moneyList = [pA*z[0] + pB*z[1] for z in L] maxMoneyIndex = moneyList.index(max(moneyList)) return L[maxMoneyIndex] (b) # main program f = open("filenames.txt", "r") namesList = [] for line in f: L = line.split(".") [month, day, year] = [int(x) for x in L[0].split("-")] [hour, minute, second] = [int(x) for x in L[1].split(":")] if withinDeadline(month, day, hour, minute, second): if not L[2] + " " + L[3] in namesList: namesList.append(L[2] + " " + L[3]) print(namesList)