The chapter shows how a dictionary provides a clever way to count the number of unique words. For those familiar with sets, there's yet an easier way to do this (using Python's set type).
1 2 3 4 5 6 7
def uCount(fname): F = open(fname) ewords = [ w in F.read().split() if 'e' in w ] uniqs = set(words) p = 100*len(eWords)/float(len(uniqs)) return int(p)
Line 3 (actually lines 3 and 4) makes a list of all the "e"-words in a file, and line 5 defines the set of such words.