title: How to categorize list of dictionaries based on the value of a key in python efficiently?
body: <p>I have a list of dictionaries in python which I want to categorized them based on the value of a key which exists in all dictionaries and process each category separately. I don't know what are the values, I just know that there exists a special key. Here's the list:</p>
  
  <pre><code>dictList = [
              {'name': 'name1', 'type': 'type1', 'id': '14464'}, 
              {'name': 'name2', 'type': 'type1', 'id': '26464'},
              {'name': 'name3', 'type': 'type3', 'id': '36464'},
              {'name': 'name4', 'type': 'type5', 'id': '43464'},
              {'name': 'name5', 'type': 'type2', 'id': '68885'}
              ]
  </code></pre>
  
  <p>This is the code I currently use:</p>
  
  <pre><code>while len(dictList):
      category = [l for l in dictList if l['type'] == dictList[0]['type']]
      processingMethod(category)
      for item in category:
          dictList.remove(item)
  </code></pre>
  
  <p>This iteration on the above list will give me following result:</p>
  
  <pre><code>Iteration 1:
              category = [
                          {'name': 'name1', 'type': 'type1', 'id': '14464'}, 
                          {'name': 'name2', 'type': 'type1', 'id': '26464'},
                          ]
  
  Iteration 2:
              category = [
                          {'name': 'name3', 'type': 'type3', 'id': '36464'}
                          ]
  
  Iteration 3:
              category = [
                          {'name': 'name4', 'type': 'type5', 'id': '43464'}
                          ]
  
  Iteration 4:
              category = [
                          {'name': 'name5', 'type': 'type2', 'id': '68885'}
                          ]
  </code></pre>
  
  <p>Each time, I get a category, process it and finally remove processed items to iterate over remaining items, until there is no remaining item. Any idea to make it better?</p>