On Jun 14, 4:05 pm, sturlamolden <[EMAIL PROTECTED]> wrote:
> On Jun 12, 3:48 pm, Mark <[EMAIL PROTECTED]> wrote:
>
> > Is this possible?
>
> def foobar(user,score):
> sums = {}
> for u,s in zip(user,score):
> try:
> sums[u] += s
> except KeyError:
> sums[u] = s
> return [(u, sums[u]) for u in sums].sort()
>
sort() sorts the list in-place and returns None. Try this instead:
return sorted([(u, sums[u]) for u in sums])
or, better yet:
return sorted(sums.items())
> usersum = foobar(user,score)
> for u,s in usersum:
> print "%d %d" % (u,s)
--
http://mail.python.org/mailman/listinfo/python-list