[Tutor] Averaging a list of lists with a listcomp?

Terry Carroll carroll at tjc.com
Thu Apr 26 09:09:18 CEST 2007


On Thu, 26 Apr 2007, John Fouhy wrote:

> So, here is your one-line solution:
> 
> >>> [sum(x)/len(x) for x in zip(*orig)]
> [30, 20, 50]

Beautiful.  Thanks.

I wasn't looking for a one-liner, exactly, but just something that was 
more straightforward and pythonic than what I was doing.  But I find that 
that's often what one-liners are, as long as they aren't one-liners for 
one-linerness's sake!



More information about the Tutor mailing list