re - whether|unless\b,re.I count = 0 words = 0 for sent in...

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

View Full Document Right Arrow Icon
import re filename='text3.txt' # read in file text = open(filename,'r').read() # replace newlines with spaces text = text.replace('\n',' ') # split into sentences text = re.split(r'[.?!]',text) sentences = len(text) # count matches pattern = re.compile(r'\b(and|but|because|or|nor|until|while|although|before|after|
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: whether|unless)\b',re.I) count = 0 words = 0 for sent in text: words += len(sent.split()) if count += 1 print count, words...
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