How to implement __iter__(self) for a container object (Python)
<p>I have written a custom container object.</p>

<p>According to <a href="http://docs.python.org/release/2.5.2/ref/sequence-types.html" rel="nofollow">this page</a>, I need to implement this method on my object:</p>

<pre><code>__iter__(self)
</code></pre>

<p>However, upon following up the link to <a href="http://docs.python.org/release/2.5.2/lib/typeiter.html" rel="nofollow">Iterator Types</a> in the Python reference manual, there are no examples given of how to implement your own.</p>

<p>Can someone post a snippet (or link to a resource), that shows how to do this?</p>

<p><strong>[Edit]</strong></p>

<p>The container I am writing, is a map (i.e. stores values by unique keys).
dicts can be iterated like this:</p>

<p>for k, v in mydict.items()</p>

<p>In this case I need to be able to return two elements (a tuple?) in the iterator. 
It is still not clear how to implement such an iterator (despite the several answers that have been kindly provided). Could someone please shed some more light on how to implement an iterator for a map-like container object? (i.e. a custom class that acts like a dict)?</p>
