IntroCModelingLA/Code/frequencyNFW.py
def countWords(words, filename):
	"""Counts words in file and returns dictionary."""
	try:
		file = open(filename, "r")
		for x in file.readlines():
			for i in string.split(x):
				i = string.strip(string.lower(i))
				if len(i) == 0:
					continue
				while i[-1] in string.punctuation:
					i = i[:-1]
					if len(i) == 0:
						break
				if len(i) == 0:
					continue
				while i[0] in string.punctuation:
					i = i[1:]
					if len(i) == 0:
						break
				if i in functionWordsEN:
					continue
				if words.has_key(i):
					# increment the count of this word
					words[i][0] += 1
				else:
					# append the word and its length
					words[i] = [ 1, len(i) ]
	except IOError:
		print "Cannot read from file:", filename
		file.close()
	else:
		file.close()
	return words
Counts words in file and returns dictionary.
Counts words in file and returns dictionary.
Counts words in file and returns dictionary .
def countWords(words, filename):
	try:
		file = open(filename, "r")
		for x in file.readlines():
			for i in string.split(x):
				i = string.strip(string.lower(i))
				if len(i) == 0:
					continue
				while i[-1] in string.punctuation:
					i = i[:-1]
					if len(i) == 0:
						break
				if len(i) == 0:
					continue
				while i[0] in string.punctuation:
					i = i[1:]
					if len(i) == 0:
						break
				if i in functionWordsEN:
					continue
				if words.has_key(i):
					words[i][0] += 1
				else:
					words[i] = [ 1, len(i) ]
	except IOError:
		print "Cannot read from file:", filename
		file.close()
	else:
		file.close()
	return words
def countWords ( words , filename ) : try : file = open ( filename , "r" ) for x in file . readlines ( ) : for i in string . split ( x ) : i = string . strip ( string . lower ( i ) ) if len ( i ) == 0 : continue while i [ - 1 ] in string . punctuation : i = i [ : - 1 ] if len ( i ) == 0 : break if len ( i ) == 0 : continue while i [ 0 ] in string . punctuation : i = i [ 1 : ] if len ( i ) == 0 : break if i in functionWordsEN : continue if words . has_key ( i ) : words [ i ] [ 0 ] += 1 else : words [ i ] = [ 1 , len ( i ) ] except IOError : print "Cannot read from file:" , filename file . close ( ) else : file . close ( ) return words
Counts words in file and returns dictionary.
Counts words in file and returns dictionary .
"""Counts words in file and returns dictionary.""" # increment the count of this word # append the word and its length
words
filename