def main(*argv): "Demostration program number 4." print Demo4.main.__doc__ String.testHash() ChainedHashTable.main(*argv) ChainedScatterTable.main(*argv) OpenScatterTable.main(*argv) OpenScatterTableV2.main(*argv) return 0
def wordCounter(input, output): """ (File, File) -> None Counts the number of occurrences of each word in the given file. """ table = ChainedHashTable(1031) for line in input.readlines(): for word in line.split(): assoc = table.find(Association(word)) if assoc is None: table.insert(Association(word, Algorithms.Counter(1))) else: counter = assoc.value counter += 1 output.write(str(table) + "\n")