Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Finish the following Python CODE by adding code after the line ######### YOUR CODE STARTS HERE ################ Only modify this file. Do not copy others.
Finish the following Python CODE by adding code after the line ######### YOUR CODE STARTS HERE ################
Only modify this file. Do not copy others. If you do not know, do not answer. #### Note: In the case of dictionaries, use the keys as the determining factor for all work on the data structures #### Note: You can give preference to data structure a over b, but no use case will require that you have done this. #### This means if a is a dictionary with keys "a","b", and "c" and b is a dictionary with key of "a" #### You will not be tested as two which value for key "a" would be in the result #### Note: You will only be tested in which both data structures are the same type, no a is a list and b is a tuple. #### The result of the methods will be tested to ensure they are the same data structure as a and b def unionOfTwoDataStructures(a,b): result = None #Find the concatenation of the data structures (with no uniqueness guarantee) a and b and set the return variable 'result' to this value #Note: if you ensure that each value from a and b only occurs once, it may make other methods easier to complete #Note: While using concatenation will get you most of the way to this, it will not result in only unique values if type(a) is list and type(b) is list: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ elif type(a) is tuple and type(b) is tuple: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ elif type(a) is dict and type(b) is dict: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ else: print "a and b have to both be either lists, tuples, or dictionaries" return result def intersectionOfTwoDataStructures(a,b): result = None #Find the elements of both of the data structures a and b and set the return variable 'result' to this value #Note: if you ensure that each value from a and b only occurs once, it may make other methods easier to complete if type(a) is list and type(b) is list: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ elif type(a) is tuple and type(b) is tuple: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ elif type(a) is dict and type(b) is dict: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ else: print "a and b have to both be either lists, tuples, or dictionaries" return result def symmetricDifferenceOfTwoDataStructures(a,b): result = None #Find the elements that are not common to both data structures a and b and set the return variable 'result' to this value #Note: you may be able to use other methods together to get this done without much extra code, look up venn diagrams to see # how this could happen ######### YOUR CODE STARTS HERE ################ if type(a) is list and type(b) is list: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ elif type(a) is tuple and type(b) is tuple: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ elif type(a) is dict and type(b) is dict: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ else: print "a and b have to both be either lists, tuples, or dictionaries" ######### YOUR CODE ENDS HERE ################ return result def equalityOfTwoDataStructures(a,b): result = None #Determine if the two data structures passed in as variables are equivalent and place the associated # boolean value of True or False into the variable result ######### YOUR CODE STARTS HERE ################ if type(a) is list and type(b) is list: #Note: Equality of two lists means that they contain all of the same values, it does not mean # mean that both lists have them in same order or do not include duplicates ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ elif type(a) is tuple and type(b) is tuple: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ elif type(a) is dict and type(b) is dict: ######### YOUR CODE STARTS HERE ################ ######### YOUR CODE ENDS HERE ################ else: print "a and b have to both be either lists, tuples, or dictionaries" ######### YOUR CODE ENDS HERE ################ return result def test_all_methods(a,b): result = [] result.append(unionOfTwoDataStructures(a,b)) result.append(intersectionOfTwoDataStructures(a,b)) result.append(symmetricDifferenceOfTwoDataStructures(a,b)) result.append(equalityOfTwoDataStructures(a,b)) return result
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started