Question: Using Python 3.6: Define a function called filter_and_save() that takes a dictionary (with strings as keys and values), a list of keys, and a filename.
Using Python 3.6: 
Define a function called filter_and_save() that takes a dictionary (with strings as keys and values), a list of keys, and a filename. The function should first open a file with the given filename for writing. For each key in the list, the function should check if that key is used in the dictionary. If so, it should write the key and its associated value to a line in the file in the format key : value. If the the key is not used in the dictionary, then it should use undefined instead of the value. If an IOError is raised while working with the file, then the function should return False. If no IOError's an; raised, then it should return True. Remember to make sure that the file is closed when the function is done writing to it. For example, given the function call filter_and_save( {"yes": "no", "up" : "down" , "left": "right"}, ["up", "big", "yes"], "output .txt"), and assuming no errors are raised, the function .should return True, and the following should be the content of the file output.txt: up:down big:undefined yes:no
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
