IntroCModelingLA/Code/frequency.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(i)
				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(i)
				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 ( i ) 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