title: Robust way to sum all values corresponding to a particular objects property?
body: <p>I have an array as such.</p>
  
  <pre><code>
  items = [
    {
      "title": "title1",
      "category": "category1",
      "value": 200
    },
    {
      "title": "title2",
      "category": "category2",
      "value": 450
    },
    {
      "title": "title3",
      "category": "category1",
      "value": 100
    }
  ]
  </code></pre>
  
  <p>This array consists of many dictionaries with a property <code>category</code> and <code>value</code>.
  What is the robust way of getting an array of category objects with their <code>value</code> summed like:</p>
  
  <pre><code>
  data= [
    {
      "category": "category1",
      "value": 300
    },
    {
      "category": "category2",
      "value": 450
    }
  ]
  </code></pre>
  
  <p>I'm looking for the best algorithm or way possible for both the small array as well as the huge array. If there is an existing algorithm please point me to the source.</p>
  
  <p>What I tried??</p>
  
  <pre><code>
  data = []
  for each item in items:
      if data has a dictionary with dictionary.category == item.category:
          data's dictionary.value = data's dictionary.value + item.value
      else:
          data.push({"category": item.category, "value":item.value})
  </code></pre>
  
  <p>Note: Any programming language is welcome. Please comment before downvoting.</p>