From cda633fbb039c78a4740ef48ede34959ec6e0bd2 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sat, 23 Oct 2021 01:19:42 -0400 Subject: [PATCH] [+] A3 P2 Q2 --- assignments/a3/a3_part2.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/assignments/a3/a3_part2.py b/assignments/a3/a3_part2.py index d6186e0..2aed7ba 100644 --- a/assignments/a3/a3_part2.py +++ b/assignments/a3/a3_part2.py @@ -30,6 +30,9 @@ def update_follow_list(model: dict[str, list[str]], word: str, follow_word: str) If word is not already present in model, add it to the model with the follow list [follow_word]. Otherwise, add follow_word to the follow list of word. """ + if word not in model: + model[word] = [] + model[word].append(follow_word) def create_model_owc(text: str) -> tuple[int, dict[str, list[str]]]: @@ -43,6 +46,13 @@ def create_model_owc(text: str) -> tuple[int, dict[str, list[str]]]: - text != '' - len(str.split(text)) > 1 """ + words = text.split() + model: dict[str, list[str]] = {} + + for i in range(1, len(words)): + update_follow_list(model, words[i - 1], words[i]) + + return len(words), model ###############################################################################