Summing a 2D list

Gerhard Häring gh at ghaering.de
Thu Jun 12 11:06:24 EDT 2008


Mark wrote:
> John, it's a QuerySet coming from a database in Django. I don't know
> enough about the structure of this object to go into detail I'm
> afraid. [...]

Then let the database do the summing up. That's what it's there for :-)

select user, sum(score) from score_table
group by user

or something very similar, depending on the actual database schema. I 
don't know how to do this with Django's ORM, but is the way to do it in 
plain SQL.

-- Gerhard




More information about the Python-list mailing list