So lets say I have a list of spending transactions tlist = {{john,23},{bob,2},{john,7}...}
and I want to have a list of the total expenses per person.
I can do this procedurally by iterating over the transactions in tlist using a for loop. If their name is not yet in the expense list, I add it as a row, with the corresponding spending. If their name is in the expense list, I add the transaction amount to their total.
This is fine, but I am aware that for loops are frowned upon in Mathematica, and are relatively inefficient. So, what would be the proper, "good code" way of doing this?
Dataset[Total /@ GroupBy[tlist, First -> Last]]
$\endgroup$Dataset@GroupBy[tlist, First -> Last, Total]
$\endgroup$