title: Python: filtering a list of custom objects, by one of its dictionary attributes
body: <p>I am trying create a method within my class that has the ability to filter a list of objects in this class by one of its dictionary attributes.  For example:</p>
  <p>In the class Vehicle I created below, the <em>category</em> parameter will be given a dictionary of key: value combinations, where the value will be 1 if the Vehicle fits that category, i.e.:</p>
  <pre><code>{'convertible': 1, 'pickup': 0, 'electric': 1}
  </code></pre>
  <p>So with my class Vehicle, I could create a list of car objects:</p>
  <pre><code>class Vehicle:
      def __init__(self, name, category, price):
          self.__name = name
          self.__category = category
          self.__price = price 
  
  lst_cars = 
  [
  Vehicle('Viper', {'convertible': 1, 'pickup': 0, 'electric': 1}, 300,000), 
  Vehicle('x150', {'convertible': 0, 'pickup': 1, 'electric': 0}, 300,000), 
  Vehicle('BMW', {'convertible': 1, 'pickup': 0, 'electric': 1}, 300,000)
  ] 
  </code></pre>
  <p>I can sort my list by name using attrgetter and passing name as property with the following code:</p>
  <pre><code>def order_by(lst_cars, property):
      lst = []
      c = sorted(lst_cars, key=attrgetter(prop))
      for car in c:
          lst += [car]
      return lst
  </code></pre>
  <p>But what I really want is a method <code>parse_by(lst_cars, lst_category)</code> that takes a list of Vehicle objects and a as well as a list of category strings <code>['convertible', 'electric']</code> and it will return a list of objects that have a 1 for those category values.</p>
  <pre><code>[
  Vehicle('Viper', {'convertible': 1, 'pickup': 0, 'electric': 1}, 300,000), 
  Vehicle('BMW', {'convertible': 1, 'pickup': 0, 'electric': 1}, 300,000)
  ]  
  </code></pre>
  <p>After playing with my code a little I came up with the following that seemed to work, so edited with an answer but others below were also helpful:</p>
  <pre><code>def parse_by(lst_cars, lst_category):
      c = lst_cars
      for item in lst_category:
          c = list(filter(lambda x: x.category[item] == 1, c))
      return c
  </code></pre>