Dec-19-2017, 12:55 PM
On further reflection, you probably just want the QuarterSales field of the Sales namedtuple to be a list of QuarterlySales objects:
A dictionary (dict) is a data structure that enables you to map keys to values. So in your case, I would do something like the following.
https://docs.python.org/3/tutorial/datas...ctionaries
QuarterlySales = collections.namedtuple('QuarterlySales', ['ID', 'QuarterNo', 'QuarterSales']) Sales = collections.namedtuple('Sales', ['ID', 'QuarterSales', 'TotalSales']) sales1 = Sales(1, [QuarterlySales (1, 1, 100), QuarterlySales (2, 2, 200), ...], 350)If you want to go the dict route...
A dictionary (dict) is a data structure that enables you to map keys to values. So in your case, I would do something like the following.
https://docs.python.org/3/tutorial/datas...ctionaries
Sales = namedtuple(...) QuarterlySales = namedtuple(...) sales = {} # sales is an empty dict. The dict will map salesperson ids to lists of sales sales[1] = [ QuarterlySales(...), QuarterlySales(...), ...] # so sales person with ID 1 gets these QuarterlySales tuples... sales[2] = [ ... ] # So now when you figure out which sales person has the highest total, you can just do something like this: best_salesperson = # however you figure that out quarterlies = sales[best_salesperson.ID] # quarterlies is a list of QuarterlySalesThis is all sketchy sample/pseudo-code to get you started.