title: Loop for dictionaries in python
body: <p>I have the following script:</p>
  
  <pre><code>from collections import defaultdict
  
  class OrderLine:
     def __init__(self, shop_id, qty, price):
      self.shop_id = shop_id
      self.qty = qty
      self.price = price
  
  order_lines = [OrderLine(1, 2, 30), OrderLine(1, 1, 50), OrderLine(3, 3, 10)]
  shop_sum = defaultdict(int)
  for order_line in order_lines:
     print order_line.price
     print order_line.qty
     print order_line.shop_id
  </code></pre>
  
  <p>each line consists of (shop_id, qty, price) I want to loop for this shop_sum  to give me for each shop_id:</p>
  
  <pre><code>total_price = qty * price
  </code></pre>
  
  <p>example: I have shop ids (1,3) , in shop_id =1
  I have two order lines [OrderLine(1, 2, 30), OrderLine(1, 1, 50)]
  I want to calculate the total price for all order lines which has the same shop_id where: total_price = qty * price</p>
  
  <p>Thanks in advance</p>