Skip to content

Instantly share code, notes, and snippets.

@nathancahill
Created September 13, 2013 21:24
Show Gist options
  • Save nathancahill/6556290 to your computer and use it in GitHub Desktop.
Save nathancahill/6556290 to your computer and use it in GitHub Desktop.
Find the median of a list of values.
import argparse
import numpy
parser = argparse.ArgumentParser(description='Find the median of a list of values.')
parser.add_argument('values', metavar='N', type=float, nargs='+')
args = parser.parse_args()
values = args.values
values.sort()
median = numpy.median(values)
print 'Median: ' + str(median)
print 'Sorted: [' + ', '.join(map(str, values)) + ']'
@nathancahill
Copy link
Author

Run it in the command line: python median.py 10 4 19 20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment