From c2e434e2d305efaf361104a720aaf5f7943c9132 Mon Sep 17 00:00:00 2001 From: Boom4life1 Date: Sun, 26 Oct 2025 10:44:30 -0700 Subject: [PATCH 1/2] Fixing 10.10.14 solution --- pretext/dictionaries/writecode.ptx | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pretext/dictionaries/writecode.ptx b/pretext/dictionaries/writecode.ptx index d7d46611..ecffc0d5 100644 --- a/pretext/dictionaries/writecode.ptx +++ b/pretext/dictionaries/writecode.ptx @@ -409,20 +409,26 @@ with open("mbox-short.txt", "r") as filename: messages = filename.readlines() # Iterate through each message (each line) for message in messages: - # Assign the key to the first (0th) element of the message - key = message.split()[0] - # Assign the value to the second element of the message - value = message.split()[1] - # Check if key is already in dictionary - if key not in message_count.keys(): - # if not, add key/value pair to dictionary - message_count[key] = value + # Make sure the message has at least 2 elements + if len(message.split()) > 2: + # Assign the key to the first (0th) element of the message + key = message.split()[0] + if key == "From": + # Assign the value to the second element of the message + value = message.split()[1] + # Check if key is already in dictionary + if key not in message_count.keys(): + # if not, add key/value pair to dictionary + message_count[value] = 1 + else: + # if so, increase count for that key by 1 + message_count[value] += 1 # Create variable to count emails max_emails = 0 # Iterate through keys in dictionary for key in message_count.keys(): - # Check if key is larger than the max emails - if int(message_count[key]) >= max_emails: + # Check if the value for that key is greater than or equal to max_emails + if int(message_count[key]) >= max_emails: # If so, reassign max_emails to that key max_emails = int(message_count[key]) print(max_emails) From f7dfbef184c0eba47a1679fe482c7870bcdb4fbb Mon Sep 17 00:00:00 2001 From: Boom4life1 Date: Sun, 26 Oct 2025 10:51:07 -0700 Subject: [PATCH 2/2] Updated code for 10.10.14 solution --- pretext/dictionaries/writecode.ptx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pretext/dictionaries/writecode.ptx b/pretext/dictionaries/writecode.ptx index ecffc0d5..263a8d32 100644 --- a/pretext/dictionaries/writecode.ptx +++ b/pretext/dictionaries/writecode.ptx @@ -413,15 +413,15 @@ with open("mbox-short.txt", "r") as filename: if len(message.split()) > 2: # Assign the key to the first (0th) element of the message key = message.split()[0] - if key == "From": + if key == "From" or key == "From:": # Assign the value to the second element of the message value = message.split()[1] # Check if key is already in dictionary - if key not in message_count.keys(): - # if not, add key/value pair to dictionary + if value not in message_count.keys(): + # if not, set the value to 1 message_count[value] = 1 else: - # if so, increase count for that key by 1 + # if so, increase count for that value by 1 message_count[value] += 1 # Create variable to count emails max_emails = 0 @@ -431,6 +431,7 @@ for key in message_count.keys(): if int(message_count[key]) >= max_emails: # If so, reassign max_emails to that key max_emails = int(message_count[key]) +# Print the maximum number of emails print(max_emails)