diff options
author | Santosh G. Vattam | 2010-03-30 14:45:12 +0530 |
---|---|---|
committer | Santosh G. Vattam | 2010-03-30 14:45:12 +0530 |
commit | fd65842b0be72d2c2f502fbcb34ba3c77a8ac528 (patch) | |
tree | 03fa6a2b432ea9063a5887692353f36d611bcaed /statistics.txt | |
parent | ec4c91f86cb46fccdcfecd0cd0586cd8c5b92f17 (diff) | |
download | st-scripts-fd65842b0be72d2c2f502fbcb34ba3c77a8ac528.tar.gz st-scripts-fd65842b0be72d2c2f502fbcb34ba3c77a8ac528.tar.bz2 st-scripts-fd65842b0be72d2c2f502fbcb34ba3c77a8ac528.zip |
Added statistics.txt.
Diffstat (limited to 'statistics.txt')
-rw-r--r-- | statistics.txt | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/statistics.txt b/statistics.txt new file mode 100644 index 0000000..c9f4241 --- /dev/null +++ b/statistics.txt @@ -0,0 +1,52 @@ +Hello welcome to the tutorial on statistics and dictionaries in Python. + +In the previous tutorial we saw the `for' loop and lists. Here we shall look into +calculating mean for the same pendulum experiment and then move on to calculate +the mean, median and mode for a very large data set. + + +In []: g_list = [] +In []: for line in open('pendulum.txt'): + .... point = line.split() + .... L = float(point[0]) + .... t = float(point[1]) + .... g = 4 * pi * pi * L / (t * t) + .... g_list.append(g) + +In []: total = 0 +In []: for g in g_list: + ....: total += g + ....: + +In []: g_mean = total / len(g_list) +In []: print 'Mean: ', g_mean + +In []: g_mean = sum(g_list) / len(g_list) +In []: print 'Mean: ', g_mean + +In []: g_mean = mean(g_list) +In []: print 'Mean: ', g_mean + + +In []: d = {'png' : 'image file', + 'txt' : 'text file', + 'py' : 'python code' + 'java': 'bad code', + 'cpp': 'complex code'} + +In []: d['txt'] +Out[]: 'text file' + +In []: 'py' in d +Out[]: True + +In []: 'jpg' in d +Out[]: False + +In []: d.keys() +Out[]: ['cpp', 'py', 'txt', 'java', 'png'] + +In []: d.values() +Out[]: ['complex code', 'python code', + 'text file', 'bad code', + 'image file'] |