diff --git a/HW 2/dcs_211_hw2.py b/HW 2/dcs_211_hw2.py new file mode 100644 index 0000000..a25d15b --- /dev/null +++ b/HW 2/dcs_211_hw2.py @@ -0,0 +1,28 @@ +def parseFile(filename): + word_counts = {} + file = open(filename, 'r') + line = file.readline() + while line != "": + word=line.strip() + if word in word_counts: + word_counts[word] += 1 + else: + word_counts[word] = 1 + line = file.readline() + file.close() + return word_counts +def main(): + print("Test 1: test1.txt") + print(parseFile("test1.txt")) + print() + + print("Test 2: test2.txt") + print(parseFile("test2.txt")) + print() + + print("Test 3: test3.txt") + print(parseFile("test3.txt")) + print() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/HW 2/test1.txt b/HW 2/test1.txt new file mode 100644 index 0000000..decc90e --- /dev/null +++ b/HW 2/test1.txt @@ -0,0 +1,6 @@ +apple +banana +apple +orange +banana +apple diff --git a/HW 2/test2.txt b/HW 2/test2.txt new file mode 100644 index 0000000..fc9b2ae --- /dev/null +++ b/HW 2/test2.txt @@ -0,0 +1,4 @@ +dog +cat +bird +fish diff --git a/HW 2/test3.txt b/HW 2/test3.txt new file mode 100644 index 0000000..6043670 --- /dev/null +++ b/HW 2/test3.txt @@ -0,0 +1,3 @@ +python +python +python