title: Implementing __next__ in a custom class
body: <p>I have a class that looks like this</p>
  
  <pre><code>Class myClass:
  
      def __init__(self, key, value):
          self.key = key
          self.value = value
  </code></pre>
  
  <p>where <code>key</code> is a string and <code>value</code> is always a list of elements of myClass, possibly empty.</p>
  
  <p>I want to define my own iter method that returns <code>value.key</code> for each <code>value</code> in <code>values</code>. I tried </p>
  
  <pre><code>def __iter__(self):
      return self 
  
  def __next__(self):
      try:
          self.value.next().key
      except:
          raise StopIteration
  </code></pre>
  
  <p>but it's looping forever. What am I doing wrong?
  Also if I want to have Python 2 / 3 compatibility, should I add the method</p>
  
  <pre><code>def next(self):
      return self.__next__()
  </code></pre>