alist = [2, 3, 4, 5, 6, 7, 8] print(alist[1:4]) piece = alist[2:5] # Now we're going do do all the examples with piece # Not alist alist[3] = 243 print(piece) print(alist) piece.append("cow") print(piece) print(alist) piece[len(piece):] = ["moose"] print(piece) piece[1:3] = ["a", "b", "c"] print(piece) # Causes an out of range error # piece[len(piece)] = "extra" piece.insert(3, "fox") piece.insert(3, "fox") piece.insert(3, "fox") print(piece) # Remove the extra fox print(piece.remove("fox")) print(piece) piece.remove("fox") print(piece) piece.remove("fox") print(piece) # Don't do this! There are no more foxes # piece.remove("fox") print(piece.pop()) print(piece) print(piece.index("cow")) # Print a message if "cow" is in the list #piece.remove("cow") # Not going to work # Crashes if cow is not in the list! #if(piece.index("cow") > -1): # print("There is a cow in your list!") # print("Better than in your living room") # Works, but we don't like this try: piece.index("cow") print("There is a cow in your list!") print("Better than in your living room") except: print("Your list is cow-free!") if "cow" in piece: print("There is a cow in your list!") print("Better than in your living room") else: print("Your list is cow-free!") number_list = [4, 1, 8, 3, 4] number_list.sort() print(number_list) # Can't sort this! Compare ints to strings? #piece.sort()