Don't like this style? Click here to change it! blue.css

Lab 7: Generating Subsets

Did you know that there are \(2^n\) subsets of any set with \(n\) elements? Check it out:

\(S = \{1, 2, 3\}\) then the subsets are \(\{\},\{1\},\{2\},\{3\},\{1,2\},\{1,3\},\{2,3\},\{1,2,3\}\). The reason there are \(2^n\) is because every subset either has or does not have each of the \(n\) elements. So, in other words, you get \(n\) yes/no questions to answer to define a subset, which gives \(2 \times 2 \times \cdots \times 2\) possible answers.

Your job is to write a function which uses the itertools module to generate all subsets of given iterable.

You don't know the itertools module yet, so here is some documentation.

For example:

      
        subsets([1, 2, 3]) == [[], [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]]
      
    

Be careful not to call this on too large of an iterable, it grows slow quickly!