From f8edafd38df6b9e17465a5469be096b14b36f01c Mon Sep 17 00:00:00 2001 From: Benjamin Adovasio Date: Sat, 31 Jan 2026 12:16:54 -0500 Subject: [PATCH] finished parseWords --- HW 3/dcs211_hw3.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 HW 3/dcs211_hw3.py diff --git a/HW 3/dcs211_hw3.py b/HW 3/dcs211_hw3.py new file mode 100644 index 0000000..e79b5d9 --- /dev/null +++ b/HW 3/dcs211_hw3.py @@ -0,0 +1,24 @@ +def parseWords(filename: str) -> Dict[str, List[int]]: + words_dict: Dict[str, List[int]] = {} + + with open(filename, "r") as input_file: + line = input_file.readline() + while line != "": + for char in string.punctuation: + line = line.replace(char, "") + words = line.split() + for word in words: + key = word.lower() + + if key not in word_dict: + word_dict[key] = [0, 0] + + if word[0].isupper(): + word_dict[key][0] += 1 + + else: + word_dict[key][1] += 1 + + line = input_file.readline() + + return word_dict \ No newline at end of file