title: How can I return the number of stock sold and bought without defaultdict?
body: <p>For this problem, we are given this dictionary whose keys are names; which has tuples with 3 values: in the 3-tuple, a stock name, number of shares traded for that transaction (int), and price of each share (int).</p>
  
  <pre><code>new_dict = {
      'Carl': [('Intel', 30, 40), ('Dell' , 20, 50), ('Intel',-10, 60), 
  ('Apple', 20, 55)],
      'Barb': [('Intel', 20, 40), ('Intel',-10, 45), ('IBM',   40, 30), 
  ('Intel',-10, 35)],
      'Alan': [('Intel', 20, 10), ('Dell',  10, 50), ('Apple', 80, 80), ('Dell', 
  
  -10, 55)],
      'Dawn': [('Apple', 40, 80), ('Apple' ,40, 85), ('Apple',-40, 90)]
    }
  </code></pre>
  
  <p>I am creating a traded function that takes in new_dict and returns a dictionary where keys are all the stocks that appear in transactions; the value is a stock is a 2-list where the first index is the number of shares of that stock bought and whose second index is the number of shares of that stock sold. <strong>Bought</strong> is positive stock and <strong>sold</strong> is any stock with a negative number.</p>
  
  <p>The output of this function should be:</p>
  
  <pre><code>{'Intel': [70, 30], 'Dell': [30, 10], 'Apple': [180, 40], 'IBM': [40, 0]}
  </code></pre>
  
  <p>This is what I have so far:</p>
  
  <pre><code>def traded(database :{str: (str, int, int)}) -&gt;dict:
      result_dict = dict()
      intel = []
      dell = []
      apple = []
      ibm = []
  
  
  
      for key, val in database.items():
          pos_sum = 0
          for x in val:
              if x[1] &gt; 0:
                 pos_sum += x[1]
  
      return pos_sum
  </code></pre>
  
  <p>I am trying to do this for each stock company individually by having separate lists for each stock company, but I feel that is just tedious. I'm not sure what other techniques there are to do this for each stock company individually.</p>
  
  <p>Is there a simple, easy to understand way to do this, preferably without <code>defaultdict</code>?</p>
  
  <p>Thanks!</p>