title: 'MyClass' object has no attribute '__getitem__'
body: <p>I have a class like this one:</p>
  
  <pre><code>class MyClass(object):
      def __init__(self, id, a, b, c):
          self.myList     = []
          self.id         = id
          self.a          = a
          self.b          = b
          self.c          = c
  
      def addData(self, data):
          self.myList.append(data)
  </code></pre>
  
  <p>In my main code, I create a list of MyClass instances called <code>myClassList</code>. In a line I have to check if an item with a given <code>id</code> already exists. I do it in this way:</p>
  
  <pre><code>id = 'foo' # in real code is set dynamically 
  recent_item = next( (item for item in myClassList if item['id'] == id), None )
  </code></pre>
  
  <p>The second line in that code gives this error:</p>
  
  <blockquote>
    <p>'MyClass' object has no attribute <code>'__getitem__'</code></p>
  </blockquote>
  
  <p>How can I fix?</p>