Question: Implement (in python) a function called set-equal that takes as input two lists representing sets and returns true if the lists represent the same set

Implement (in python) a function 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!