Problem 1 ---------- (a) >>> L = ["hello", "good day", "hi", "see you", "ciao", "au revoir"] >>> L.extend(L[1].split()) >>> L ['hello', 'good day', 'hi', 'see you', 'ciao', 'au revoir', 'good', 'day'] (b) >>> L = ["hello", "good day", "hi", "see you", "ciao", "au revoir"] >>> map(len, L[2::2]) [2, 4] (c) >>> L[3].split()[1][2] 'u' (d) >>> map(range, map(len, L)[2:5]) [[0, 1], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3]] (e) >>> del L[::3] >>> L ['good day', 'hi', 'ciao', 'au revoir'] (f) >>> L = ["hello", "good day", "hi", "see you", "ciao", "au revoir"] >>> L in (L + [L]) True (g) >>> L[2] = L[2] + " " + L[1] >>> L ['hello', 'good day', 'hi good day', 'see you', 'ciao', 'au revoir'] (h) >>> L = ["hello", "good day", "hi", "see you", "ciao", "au revoir"] >>> L.insert(L.index("ciao"), "Tschuess") >>> L ['hello', 'good day', 'hi', 'see you', 'Tschuess', 'ciao', 'au revoir'] (i) >>> L = ["hello", "good day", "hi", "see you", "ciao", "au revoir"] >>> (L*3)[3:9] ['see you', 'ciao', 'au revoir', 'hello', 'good day', 'hi'] (j) >>> L.insert(0, L.pop()) >>> L ['au revoir', 'hello', 'good day', 'hi', 'see you', 'ciao'] Problem 2 --------- (a) -5 (b) 4 (c) 0 (d) -3 Problem 3 --------- #(a) def notNeighbors(word1, word2): if len(word1) != len(word2): return True count = 0 for i in range(len(word1)): if word1[i] != word2[i]: count = count + 1 if count != 1: return True else: return False #(b) #main program dictionary = loadDictionary("dictionary.txt") L = getInput() valid = True for i in range(len(L)-1): if L[i] not in dictionary or notNeighbors(L[i], L[i+1]): valid = False break if L[len(L)] not in dictionary: valid = False if not valid: print "Not a valid word sequence." if valid: print "Valid word sequence!" Problem 4 --------- def countingSort(L): countList = [0]*10 for i in range(1, 11): countList[i-1] = L.count(i) newL = [] for i in range(len(countList)): newL.extend([i+1]*countList[i]) return newL