related lists mean value (golfed)

Michael Rudolf spamfresser at ch3ka.de
Tue Mar 9 10:00:00 EST 2010


Am 09.03.2010 13:02, schrieb Peter Otten:
>>>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y]
> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0]
> Peter

... pwned.
Should be the fastest and shortest way to do it.

I tried to do something like this, but my brain hurt while trying to 
visualize list comprehension evaluation orders ;)

Regards,
Michael



More information about the Python-list mailing list