Answer the question
In order to leave comments, you need to log in
Why does groupby work like this?
I decided to use groupby to group by a common feature (the id of the related object).
The result was the following code
for k, v in groupby(order.proposal.proposal_products, key=lambda prod_cp: prod_cp.request_product_id):
lv = list(v)
print(type(k), k, lv)
<class 'int'> 25 [<ProposalProduct 11>]
<class 'int'> 28 [<ProposalProduct 12>]
<class 'int'> 24 [<ProposalProduct 10>]
<class 'int'> 28 [<ProposalProduct 14>]
Answer the question
In order to leave comments, you need to log in
I figured it out. For groupby to work correctly, the array must be sorted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question