linecount - for word in line.split words[word =...

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

View Full Document Right Arrow Icon
import sys, re file1 = 'text1.txt' def LineCount(file1): lines = {} for line in open(file1,'r'): lines[linec] = lines.get(lines,0)+1 return lines def WordCount(file1): words = {} for line in open(file1,'r'): line = re.sub(r'[^a-z ]',' ',line.lower())
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for word in line.split(): words[word] = words.get(word,0) + 1 return words a = WordCount(sys.argv[0]) words = WordCount(a) for word in sorted(words.items()): print word...
View Full Document

This note was uploaded on 09/06/2009 for the course LING 571 taught by Professor Staff during the Fall '08 term at San Diego State.

Ask a homework question - tutors are online