Problem 3: Solution 1 --------------------- def equalLengthStrings(L): # Check if list is empty if len(L) == 0: return True # Compare the lengths of the remaining strings to the first string for i in range(1, len(L)): if len(L[i]) != len(L[0]): return False return True Problem 3: Solution 2 --------------------- # One-line solution using list comprehensions def equalLengthStrings(L): return sum([abs(len(x) - len(L[0])) for x in L]) == 0 Problem 4 Solution 1 --------------------- def addSubsequence(L, i, j): sumSubsequence = 0 for k in range(i, j+1): sumSubsequence = sumSubsequence + L[k] return sumSubsequence Problem 4 Solution 2 --------------------- def addSubsequence(L, i, j): return sum(L[i:j+1]) Problem 5 Solution 1 --------------------- def deleteSubsequence(L, i, j): newL = [] for k in range(i): newL.append(L[k]) for k in range(j+1, len(L)): newL.append(L[k]) return newL Problem 5 Solution 2 --------------------- def deleteSubsequence(L, i, j): newL = L[:] del newL[i:j+1] return newL Problem 5 Solution 3 --------------------- def deleteSubsequence(L, i, j): return [L[k] for k in range(len(L)) if k < i or k > j] Problem 6 Solution 1 --------------------- def maxPairSum(L): # we assume that L has length at least two currentSum = L[0] + L[1] currentPair = [L[0], L[1]] for i in range(1, len(L)-1): if L[i] + L[i+1] > currentSum: currentSum = L[i] + L[i+1] currentPair = [L[i], L[i+1]] return currentPair Problem 6 Solution 2 --------------------- def maxPairSum(L): pairList = [[L[i], L[i+1]] for i in range(0, len(L)-1)] sumList = [sum(x) for x in pairList] index = sumList.index(max(sumList)) return pairList[index] Problem 7 Solution 1 --------------------- def minIndex(L): smallIndex = 0 for i in range(1, len(L)): if L[i] < L[smallIndex]: smallIndex = i return smallIndex Problem 7 Solution 2 -------------------- def minIndex(L): return L.index(min(L))