####Mutable objects can be changed through multiple names ####and references. This may cause confusion. Try to ####predict the output of the following scripts ####Multiple aliases ##a_list=[1] ##b_list=a_list ##b_list.append(2) ##print(a_list) ####Object in two namespaces ##def pirate(l): ## l.append("R") ## l = ["Matey"] ## return l ##l = ["A"] ##pirate(l) ##print(l) ####Multiple containment ##a_list = [] ##b_list = [a_list, a_list] ##c_list = [a_list] ##c_list[0].append("aye") ##print(b_list) ####circular references ##a_list = [2] ##a_list.append(a_list) ##print(a_list) ####Reference cycle ##a_list = [2] ##b_list = [a_list] ##a_list[0] = b_list ##print(a_list) ####Function used in the checker class exercise ##def print_board(board): ## """Displays a board made up of a list of rows, ## where each row is a list of ints""" ## for row in board: ## for item in row: ## print("{:3d}".format(item), end=" ") ## print() ####Demonstrates basic dictionary operations ##x = {} ##print("x is an empty dict:", x) ##y = { "Paul" : "Pawel", "likes":"lubi" } ##print("a dictionary for translating:",y) ###adding an element ##y["computers"] = "komputery" ##print("looking up y['computers']:", y["computers"]) ###length of a dict ##print("y has", len(y), "keys") ###testing membership ##print("checking if 'Paul' is in y:", "Paul" in y) ##print("checking if 'Bob' is in y:", "Bob" in y) ###dicts are iterable ##for key in y: ## print(key, "translated is", y[key]) ###iterating through values is a bit trickier ##print("the values in y: ", end="") ##for value in y.values(): #y.values returns an iterable called a view ## print(value, end=" ") ###can also iterate through keys and values at the same time ##print("the key-value pairs in y: ", end="") ##for key, value in y.items(): #also returns an iterable called a view ## print(key,", which translates to", value) ###A short translation script ##msg = "Paul really likes to program computers" ##m_list = msg.split() #creates a list of words ## #### Add code to check if each word in m_list is in y. #### If it is, replace it with its value in y. ## ##msg= " ".join(m_list) #glues a list of strings back together ##print(msg)