{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ttrbeta2 - lines = lines 1 words = words len(line.split for...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#!/usr/bin/env python ##ttr.py calculates the type to token ratio import sys,re def cmpItems(x,y): return -cmp(x[1],y[1]) #assigns key and value lines = 0 words = 0 types = {} for line in sys.stdin.readlines(): #reads in file
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: lines = lines + 1 words = words + len(line.split()) for token in line.split(): #separates words with a new line types[token] = types.get(token,0) + 1 #counts tokens print words print len(types)...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online