Created
September 13, 2013 21:24
-
-
Save nathancahill/6556290 to your computer and use it in GitHub Desktop.
Find the median of a list of values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) + ']' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run it in the command line:
python median.py 10 4 19 20