title: Python: Understanding dictionary view objects
body: <p>I've been trying to understand built-in view objects return by <code>.items()</code>, <code>.values()</code>, <code>.keys()</code> in Python 3 or similarly by <code>.viewitems()</code>, <code>.viewvalues()</code>, <code>.viewkeys()</code>. There are other threads on that subject but none (even the <a href="https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects" rel="noreferrer">doc</a>) seems to described how they work internally. </p>
  
  <p>The main gain here seems to be efficienty compared to the copy of type <code>list</code> returned in Python 2. There are often compared to a <strong><em>window</em></strong> to the dictionnary items (like in this <a href="https://stackoverflow.com/questions/8957750/what-are-python-dictionary-view-objects">thread</a>).</p>
  
  <p>But what is that <strong><em>window</em></strong> and why is it more efficient ?</p>
  
  <p>The only thing I can see is that the view objects seems to be  <em>set-like</em> objects, which are generally faster for membership testing. But is this the only factor ?</p>
  
  <p><strong>Code sample</strong></p>
  
  <pre><code>&gt;&gt;&gt; example_dict = {'test':'test'}
  &gt;&gt;&gt; example_dict.items()
  dict_items([('test', 'test')])
  &gt;&gt;&gt; type(example_dict.items())
  &lt;class 'dict_items'&gt;
  </code></pre>
  
  <p>So, my question is regarding this <code>dict_items</code> class. How does that work internally?</p>