Summing a 2D list
Aidan
aweraw at gmail.com
Thu Jun 12 10:45:46 EDT 2008
Aidan wrote:
> 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.
>>
>> Aidan, I got an error trying your suggestion: 'zip argument #2 must
>> support iteration', I don't know what this means!
>
> well, if we can create 2 iterable sequences one which contains the user
> the other the scores, it should work
>
> the error means that the second argument to the zip function was not an
> iterable, such as a list tuple or string
>
> can you show me the lines you're using to retrieve the data sets from
> the database? then i might be able to tell you how to build the 2 lists
> you need.
>
wait you already did...
predictions = Prediction.objects.all()
pairs = [(p.predictor.id,p.predictionscore) for p in predictions]
those 2 lines will will build a list of user/score pairs. you can then
replace the call to zip with pairs
any luck?
More information about the Python-list
mailing list