Question: Write a Python function powerSet() that takes in a finite list object A and returns P(A), the power set of A. The output should be

 Write a Python function powerSet() that takes in a finite list

Write a Python function powerSet() that takes in a finite list object A and returns P(A), the power set of A. The output should be only in the form of list objects. Note: Make sure you are familiar with some of Python's basic built-in list functions and operators, as they will make completing this problem far easier. For example: Test A = [0, 1, 2] output = set([frozenset(a) for a in power Set(A)]) expected = [[], [0], [0, 1], [2], [1], [0, 2], [1, 2], [0, 1, 2]] expected = set([frozenset(a) for a in expected]) print (output=rexpected) A = ['a', 'b', 'c', 'd'] output = set([frozenset(a) for a in powerSet(A)]) expected = [[], ['a'], ['b'], ['a', 'b'], ['c'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c'], ['d'], ['a', 'd'], [ expected = set([frozenset(a) for a in expected]) print (output==expected)

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!