Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the following Python CODE. Only modify this file. Put code in after the line ######### YOUR CODE STARTS HERE ################ #### Note: In the

Complete the following Python CODE. Only modify this file. Put code in after the line ######### YOUR CODE STARTS HERE ################ #### 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

What is Accounting?

Answered: 1 week ago

Question

Define organisation chart

Answered: 1 week ago