Question
Implement (in python) a scheme predicate called set-equal that takes as input two lists representing sets and returns true if the lists represent the same
Implement (in python) a scheme predicate called set-equal that takes as input two lists representing sets and returns true if the lists represent the same set and false otherwise. Thus, the call:
set-equal ( [ 1, [2, [3, 4]]] [ [[4 ,3], 2], 1]]]] ) should return True
and the call
set-equal ( [ 1, [2, [3, 4]]], [ [4, 3 ,2], 1]]]] ) should return False.
Note that here sets can themselves contain sets.Hint: first, remember that set-equality is not primitive. To say that two sets A and B are equal is equivalent to saying that A is a subset of B and B is a subset of A. So first define a procedure setSubset roughly in this way: setSubset (A,B)
if the first element of A is not a set, then find out if it is a member of B (use Pythons build-in in operator)if the first element of A is a set, then find out if there is an identical set within B Thus, if the first element of B is a set, determine whether every element of the first element of A is in the first element of B And if the first element of B is not a set, continue on look for the first element of A in the remainder of B
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