Question: I created this function for my homework for python 3.5 and my teacher emailed us back and said that we could not use comprehension, but
def powerset (A) ""Build the powerset of A Given a set A, the powerset of A is the set of all subsets of A. Hint: recursion, anyone? no, really, you need to use recursion see lecture for the way to think about powerset recursively Hint: there are two base cases to the recursion: first base case: size of A is 0 second base case: size of A is 1 Hint: when you are changing a list, cloning makes it safer Hint: you may not want to test this function on a set of size 40 unless you are very patient, are not concerned about the due date, and have a lot of spare cash for memory upgrades if that is not clear, watch the Eames video again) >>> powerSet (1,21 Params: A (list): finite set of integers, represented internally as a Returns: (1ist) powerset of A, represented internally as a list if len (A)0 or len (A)1 else: , 121, 11,21 1ist return t111 bear-. A.pop () # element pulled from list return powerset (A:)+[(bear] +x tor x in powerset (A)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
