title: Python Power Set of a List
body: <p>I am trying to implement a function to generate the powerset of a list <code>xs</code>. </p>
  
  <p>The general idea is that we walk through the elements of <code>xs</code> and choose whether to include <code>x</code> or not. The problem I'm facing is that <code>withX</code> ends up being equal to <code>[None]</code> (a singleton list with <code>None</code>) because (I think) <code>s.add(x)</code> returns <code>None</code>. </p>
  
  <p>This isn't a homework assignment, it's an exercise in Cracking the Coding Interview.</p>
  
  <pre><code>def powerSetBF(xs):
      powerSet = [] 
      powerSet.append(set([]))
      for x in xs:
          powerSetCopy = powerSet[:]
          withX = [s.add(x) for s in powerSetCopy] # add x to the list of sets 
          powerSet = powerSet.extend(withX) # append those entries
      return powerSet
  </code></pre>