I have 3 classes: Group, Customer, Product. Each group contains a list of Customer [C1, C2, C3,...] and each Customer contains a list of products he wants to buy [P1,P2,P3,...]. At the top level i want to do various aggreggation, for example how much is worth the total order. I end up having for nested loops that are very slow as the number of groups, customers and products increase
total_order = 0
for customer in group:
for product in customer:
total_order += product.price * product.amount
What would you recommend in terms of structuring the code to make it much faster?