Created
October 14, 2014 14:50
-
-
Save jdherman/6b5aefd212b465f48d4a to your computer and use it in GitHub Desktop.
syllabus keywords in python
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 glob | |
| kw = ['climate', 'decision theory', 'dynamic', 'economics', 'game theory', 'heuristic', 'hydrology', | |
| 'integer', 'linear', 'model', 'nonlinear', 'policy', 'probability', 'statistics', | |
| 'stochastic','quality'] | |
| files = glob.glob('*.txt') | |
| courses_including = {} | |
| avg_count = {} | |
| for k in kw: | |
| courses_including[k] = 0 | |
| avg_count[k] = 0 | |
| for f in files: | |
| total = 0 | |
| for line in open(f): | |
| if k in line.lower(): | |
| if total == 0: | |
| courses_including[k] += 1 | |
| total += 1 | |
| avg_count[k] += total | |
| avg_count[k] /= courses_including[k] | |
| for k,v in courses_including.iteritems(): | |
| print '%s,%d,%d' % (k,v,avg_count[k]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment