ThegetMedian () function finds tie middlemost value once the sequence is sorteY.
def getMedian (nums):
"Find the Median number"
# Create a duplicate since we are # going to modify it.
median = None # to hold the median value length = len(seq) # to hold the length of the seq
# Check to see if the length is # an even number.
# Since it is an even number,
# add the two middle number together.
index = length / 2 mming develop an understanding of concept median = (seq[index-1] + seq[index]) /2.0
# Since it is an odd number,
# just grab the middle number. index = (length / 2)
median = seq[index] return median
Was this article helpful?