RE: Mean, median, and mode - third time's the charm!!!

Discussion in 'Python' started by Frohnhofer, James, Dec 6, 2004.

  1. >
    > median = lambda x: x.sort() or ((len(x) % 2) and (x[(len(x)>>1)])) or
    > (sum(x[((len(x)>>1)-1):(len(x)>>1)+1])/2.0)
    >
    > >>> median( [2,3,4,5,6,7])

    > 4.5
    > >>> median( [2,3,4,5,6])

    > 4


    How about

    >>> median = lambda x: x.sort() or (x[(len(x)-1)/2] + x[len(x)/2])/2.0
    >>> median([2,3,4,5,6,7])

    4.5
    >>> median( [2,3,4,5,6])

    4.0
    >>>



    ==============================================================================
    This message is for the sole use of the intended recipient. If you received
    this message in error please delete it and notify us. If this message was
    misdirected, CSFB does not waive any confidentiality or privilege. CSFB
    retains and monitors electronic communications sent through its network.
    Instructions transmitted over this system are not binding on CSFB until they
    are confirmed by us. Message transmission is not guaranteed to be secure.
    ==============================================================================
    Frohnhofer, James, Dec 6, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Brewer

    RE: Mean, median, and mode

    Robert Brewer, Dec 5, 2004, in forum: Python
    Replies:
    5
    Views:
    425
    Paul McGuire
    Dec 6, 2004
  2. Alfred Canoy

    Re: Python-Help ( Mean,Median & Mode)

    Alfred Canoy, Dec 5, 2004, in forum: Python
    Replies:
    2
    Views:
    11,084
    Dan Bishop
    Dec 6, 2004
  3. Josiah Carlson

    Re: Mean, median, and mode

    Josiah Carlson, Dec 6, 2004, in forum: Python
    Replies:
    7
    Views:
    454
    Steven Bethard
    Dec 6, 2004
  4. John J Lee
    Replies:
    3
    Views:
    455
    bruno at modulix
    Dec 1, 2005
  5. Edward Loper
    Replies:
    0
    Views:
    444
    Edward Loper
    Aug 7, 2007
Loading...

Share This Page