title: Add a dictionary to a `set()` with union
body: <p>I just ran across something interesting that I thought I'd ask about.</p>
  <p>Adding a dictionary to a <code>set</code>, I had assumed that the dictionary would be added as a full dictionary, it isn't. Only the keys are added:</p>
  <pre><code>dicty = {&quot;Key1&quot;: &quot;Val1&quot;, &quot;Key2&quot;: &quot;Val2&quot;}
  setunion = set()
  setunion.union(dicty)
  =&gt; set(['Key2', 'Key1'])
  </code></pre>
  <p>When you attempt to add it using <code>set.add()</code> you get an error:</p>
  <pre><code>setadd = set()
  setadd.add(dicty)
  Traceback (most recent call last):
    File &quot;python&quot;, line 1, in &lt;module&gt;
  TypeError: unhashable type: 'dict'
  </code></pre>
  <p>Obviously, this behaviour is very different from lists:</p>
  <pre><code>   listy = []
     listy.append(dicty)
     listy
  =&gt; [{'Key2': 'Val2', 'Key1': 'Val1'}]
  </code></pre>
  <p><a href="https://docs.python.org/3.4/library/stdtypes.html?highlight=set#set-types-set-frozenset" rel="noreferrer">In the docs</a> it says that sets are unordered collections of <em>hashable</em> objects, which is a hint to some of the issues above.</p>
  <h1>Questions</h1>
  <p>What's going on here? Set items have to be hashable, so clearly that has to do with why I'm only adding the keys to the set with <code>.union()</code>, but why the error with <code>.add()</code>?</p>
  <p>Is there some usability reason behind the difference in behavior of sets from lists?</p>
  <p>Is there a datatype in Python (or a library) that essentially functions like a list, but only keeps unique items?</p>