From a49b1c0d4a7ee00d047b7ee05412096fb8878d97 Mon Sep 17 00:00:00 2001 From: Benjamin Adovasio Date: Sun, 25 Jan 2026 23:44:19 -0500 Subject: [PATCH] Finished hw 2 --- HW 2/dcs_211_hw2.py | 28 ++++++++++++++++++++++++++++ HW 2/test1.txt | 6 ++++++ HW 2/test2.txt | 4 ++++ HW 2/test3.txt | 3 +++ 4 files changed, 41 insertions(+) create mode 100644 HW 2/dcs_211_hw2.py create mode 100644 HW 2/test1.txt create mode 100644 HW 2/test2.txt create mode 100644 HW 2/test3.txt 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