title: Python remove set from set
body: <p>According to my interpretation of Python 2.7.2 documentation for <a href="http://docs.python.org/library/stdtypes.html#set-types-set-frozenset" rel="noreferrer">Built-In Types 5.7 Set Types</a>, it should be possible to remove the elements of set A from set B by passing A to <code>set.remove(elem)</code> or <code>set.discard(elem)</code></p>
  
  <p>From the documentation for 2.7.2:</p>
  
  <blockquote>
    <p>Note, the elem argument to the <code>__contains__()</code>, <code>remove()</code>, and <code>discard()</code>
    methods may be a set.</p>
  </blockquote>
  
  <p>I interpret this to mean that I can pass a <code>set</code> to <code>remove(elem)</code> or <code>discard(elem)</code> and all those elements will be removed from the target set. I would use this to do something weird like remove all vowels from a string or <a href="https://stackoverflow.com/questions/5951961/how-can-i-remove-all-instances-of-a-single-set-item-in-set-a-from-set-b">remove all common words from a word-frequency histogram</a>. Here's the test code: </p>
  
  <pre><code>Python 2.7.2 (default, Jun 12 2011, 14:24:46) [M...
  Type "help", "copyright", "credits" or "license"
  &gt;&gt;&gt; a = set(range(10))
  &gt;&gt;&gt; b = set(range(5,10))
  &gt;&gt;&gt; a
  set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
  &gt;&gt;&gt; b
  set([8, 9, 5, 6, 7])
  &gt;&gt;&gt; a.remove(b)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  KeyError: set([8, 9, 5, 6, 7])
  &gt;&gt;&gt; a.discard(b)
  &gt;&gt;&gt; a
  set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
  &gt;&gt;&gt;
  </code></pre>
  
  <p>Which I expect to return:</p>
  
  <pre><code>&gt;&gt;&gt; a
  set([0, 1, 2, 3, 4])
  </code></pre>
  
  <p>I know I can accomplish this with <code>a.difference(b)</code> which returns a new set; or with a <code>set.difference_update(other)</code>; or with set operators <code>a -= b</code>, which modify the set in-place. </p>
  
  <p>So is this a bug in the documentation? Can <code>set.remove(elem)</code> actually not take a set as an argument? Or does the documentation refer to sets of sets? Given that <code>difference_update</code> accomplishes my interpretation, I'm guess the case is the latter.</p>
  
  <p>Is that unclear enough?</p>
  
  <p><strong>EDIT</strong>
  After 3 years of additional (some professional) python work, and being recently drawn back to this question, I realize now what I was actually trying to do could be accomplished with:</p>
  
  <pre><code>&gt;&gt;&gt; c = a.difference(b)
  set([0,1,2,3,4])
  </code></pre>
  
  <p>which is what I was originally trying to get.</p>
  
  <p><strong>EDIT</strong>
  After <em>4 more years</em> of python development... I realize this operation can be expressed more cleanly using set literals and the <code>-</code> operator; and that it is more complete to show that set difference is non-commutative.</p>
  
  <pre><code>&gt;&gt;&gt; a={0,1,2,3}
  &gt;&gt;&gt; b={2,3,4,5}
  &gt;&gt;&gt; a-b
  set([0, 1])
  &gt;&gt;&gt; b-a
  set([4, 5])
  </code></pre>