Mean, median, and mode

Josiah Carlson jcarlson at uci.edu
Mon Dec 6 12:51:47 EST 2004


"Robert Brewer" <fumanchu at amor.org> wrote:
> 
> Josiah Carlson wrote:
> > sean_mcilroy at yahoo.com (Sean McIlroy) wrote:
> > > 
> > > >>> median = lambda x: (max(x)-min(x))/2
> > 
> > That is /not/ the median in the general case.
> > 
> > median = lambda x: x.sort() or x[len(x)//2]
> 
> That...is a really sneaky use of null return values. I like. :)

Thank you, I'm just using a paradigm (exploiting lambdas) that I picked
up while going through various functional programming modules.

If you're really good, you can do crazy stuff with list comprehensions.
I'll leave that exercise up to the reader, as many of my examples are
in for-pay code.


 - Josiah




More information about the Python-list mailing list