title: Filtering a List of Objects by multiple Object Attributes
body: <p>I am building a Google App Engine application (Python 2.7) using the NDB API.  I am new to python development and have a feeling this is a question that has been answered before, but I have been unable to find, through my search efforts, something resembling this problem/solution. I decided to pose my question here.    </p>
  
  <p>I have a Document model class that I need to query and get the most "current" Documents.  Specifically, I want to get a list of document objects(entities) with distinct document names and whose <code>expiration</code> date (a <code>datetime.date</code> object) is the greatest value. </p>
  
  <p>For example, a query of documents in descending order by expiration date such as:  </p>
  
  <pre><code>documents = Document.query().order(-Document.expiration).fetch()
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>[{"name": "DocumentC", "expiration": datetime.date(2015, 3, 1)},
   {"name": "DocumentA", "expiration": datetime.date(2014, 4, 1)},
   {"name": "DocumentB", "expiration": datetime.date(2014, 2, 15)},
   {"name": "DocumentA", "expiration": datetime.date(2014, 1, 1)}] 
  </code></pre>
  
  <p>Based on these query results, I want to remove the second (older) occurrence of "DocumentA" and get something like this:</p>
  
  <pre><code>[{"name": "DocumentC", "expiration": datetime.date(2015, 3, 1)},
   {"name": "DocumentA", "expiration": datetime.date(2014, 4, 1)},
   {"name": "DocumentB", "expiration": datetime.date(2014, 2, 15)}]
  </code></pre>
  
  <p>My solution is:</p>
  
  <pre><code>def current_docs(docs):
      output = []
      for d in docs:
          if not any(o['name'] == d['name'] for o in output):
              output.append(d)
      return output
  
  cd = current_docs(documents)
  # returns:
  # [{'expiration': datetime.date(2015, 3, 1), 'name': 'DocumentC'},
  # {'expiration': datetime.date(2014, 4, 1), 'name': 'DocumentA'},
  # {'expiration': datetime.date(2014, 2, 15), 'name': 'DocumentB'}]
  </code></pre>
  
  <p>This seems to give me the result I expect, but:</p>
  
  <ol>
  <li>Is there a better way to filter the original query to get the results I want from the start?</li>
  <li>If not, is there a better, more efficient approach than my solution?</li>
  </ol>