title: Python list_of_tuples: sum second val of each tuple, only if first val of tuple == something
body: <p>I have a list of "tagged" tuples...where each tuple is (tag_id, value)...like so:</p>
  
  <pre><code>my_list = [(tag_A, 100), (tag_A, 200), (tag_A, 300), (tag_A, 400), (tag_B, 400), (tag_B, 600)]
  </code></pre>
  
  <p>I want to sum the values of each tuple with the same tag...so that:</p>
  
  <pre><code>sum_of_all_values_with_tag_A() = 1000
  
  sum_of_all_values_with_tag_B() = 1000
  </code></pre>
  
  <p>I can't figure out a simple Pythonic way of doing that.</p>
  
  <pre><code>sum(set(value for tag_id, value in my_list)) 
  </code></pre>
  
  <p>...returns the sum of ALL the values.</p>
  
  <p>I suppose I can wrap that with a for or a while loop, so that only tuples with the tag I want to sum are touched by that expression...?  I need to sum the values associated with both tags...resulting in two different totals, differentiated as above. But can't quite grok an elegant syntax for such a thing.</p>
  
  <p>This is happening inside of a pre-existing function.  Would be great to do it without nesting functions.</p>
  
  <p>Any suggestions are appreciated!</p>