title: how to sort dictionary inside list and manipulate data?
body: <p>I am working on something like inventory management, I am stuck in sorting and adding duplicae item by some condiiton. My code is down below and its working fine up to the data is in list  "print(c.data_dict)" </p>
  
  <pre><code>import datetime
  from itertools import groupby
  from operator import itemgetter
  
  class Supplier:
      def __init__(self, name, address, email, contact_no):
          self.name = name
          self.address = address
          self.email = email
          self.contact_no = contact_no
  
  class Product:
     def __init__(self, name):
          self.name = name
  
  class Company(Supplier, Product):
      data_dict = []
      def purchase(self, supplier_obj, product_obj, qty, date):
      self.data_dict.append({'supplier': supplier_obj.name, 'product': product_obj.name, 'qty': qty, 'date': date})
      return self.data_dict
  
  s1 = Supplier('Amazon', 'kalawad road', 'amazon@gmail.com', '987686')
  s2 = Supplier('Flipkart', 'university road', 'flipkart@gmail.com', '657457')
  s3 = Supplier('Alibaba', 'china town road', 'alibaba@qq.com', '365213')
  
  p1 = Product('Laptop')
  p2 = Product('printer')
  p3 = Product('computer')
  
  c = Company(None, None, None, None)
  c.purchase(s1, p1, 10, '2019-10-10')
  c.purchase(s1, p1, 10, '2019-10-10')
  c.purchase(s1, p2, 20, '2018-11-11')
  c.purchase(s1, p2, 30, '2018-12-12')
  c.purchase(s1, p3, 40, '2016-10-10')
  c.purchase(s2, p3, 10, '2019-11-11')
  c.purchase(s2, p3, 11, '2019-11-11')
  c.purchase(s3, p1, 6, '2019-03-04')
  c.purchase(s3, p3, 9, '2019-02-02')
  print(c.data_dict)
  </code></pre>
  
  <p>i get list containing like </p>
  
  <pre><code>[{'supplier': 'Amazon', 'product': 'Laptop', 'qty': 10, 'date': '2019-10-10'}, 
   {'supplier': 'Amazon', 'product': 'Laptop', 'qty': 10, 'date': '2019-10- 10'}, 
  {'supplier': 'Amazon', 'product': 'printer', 'qty': 20, 'date': '2018-11-11'},
   {'supplier': 'Amazon', 'product': 'printer', 'qty': 30, 'date': '2018-12-12'},
   {'supplier': 'Amazon', 'product': 'computer', 'qty': 40, 'date':'2016-10-10'},
   {'supplier': 'Flipkart', 'product': 'computer', 'qty': 10,'date': '2019-11-11'},
   {'supplier': 'Flipkart', 'product': 'computer', 'qty': 11, 'date': '2019-11-11'},     
  {'supplier': 'Alibaba', 'product': 'Laptop', 'qty': 6, 'date': '2019-03-04'}, 
  {'supplier': 'Alibaba', 'product':'computer', 'qty': 9, 'date': '2019-02-02'}]
  </code></pre>
  
  <p>where Amazon, FLipkart &amp; allibaba is Supplier Name,  Laptop-Printer-Computer is product name and qty is quantity and date is also there.</p>
  
  <p>I am trying to do sort above list in a way that if same date from same supplier is there, qty should be added. eg. in Amazon-- qty of printer should be 50 , as show in output.   How can i do it? 
  i have tried with itertool and operator module to get it done, but not getting proper output.</p>
  
  <p>My expexcted output is </p>
  
  <pre><code>sample output
  
   Amazon
   01-01-2019      laptop       10
   02-02-1019      laptop       10
   03-03-2019      printer      50
   03-03-2019      computer     40
  
   Flipkart
   01-01-2019      computer      10
   31-01-2019      computer      11
  
   Alibaba
   2019-03-04      laptop        6
   2019-02-02      computer      6
  </code></pre>