# Course evaluations

Your thoughts on what works well, and what would improve the course, will be valued. Thanks.

# Applications of pseudo-random numbers, cont'd

## Job/marriage problem

Algorithm performance: The figures below show the fraction of trials in which your algorithm chose one of the top k offers, for k from 1 to n. An (impossibly) perfect algorithm would have a horizontal line at 1.0 all the way across. Purely random choice will give a straight line from (1,1/n) to (1,1). If your name does not appear, it means your code gave an error on import. If your curve is horizontal at zero, it means your function gave an error when called.

test_marriage_job_algorithms.ipynb

## Germ avoidance problem

Code to start from: germ_avoidance_starter_code.ipynb

# Computing with text

## Grab an online document

import requests
r = requests.get("http://eff.org")
giantstring = r.text
print giantstring[:500]


## Slurp a file on disk

with open('hamlet.txt') as f:


or may need

with open('hamlet.txt',encoding='utf8') as f:


## Search for a phrase

if 'To be or not' in giantstring:
print 'Yep, it's in there.'
print giantstring.find('To be or not')


There is also a count() function.

## Clean up and count words

Most useful methods of strings: split, replace, slicing with [:], lower, join

Occasionally useful: title/capitalize, startwith/endswith

The string module has some useful things, including: string.punctuation, string.whitespace

Exercise: Count number of distinct words

## Word count

Exercise: Make a dictionary whose keys are all the distinct words in your text, and the value is the number of times the word occurs.

Exercise: Examine the relationship between word frequency and frequency rank.

Other texts of possible interest:

If time permits, make up a totally random text and compare. (Use numpy.random.choice to pick a bunch of letters at random from an alphabet of your choosing.)