Skip to content

Activity: 10.10.14 ActiveCode (dict_writecode9a) Solution Index Out of Bounds issue #416

@lukesg08

Description

@lukesg08

What Course are you in
CMSC-254-001-F2023
Python for Everybody - Interactive
What Page were you on
https://runestone.academy/ns/books/published/CMSC-254-001-F2023/dictionaries/writecode.html
10.10. Write Code Questions: Activity: 10.10.14 ActiveCode (dict_writecode9a)

What is your username
gusukumals@vcu.edu

Describe the bug
IndexError: list index out of range on line 10
is produced when running the answer code.

Javascript Errors
No errors...but:
running {"div_id":"dict_writecode9a","code":"# Open file in read mode\nwith open("mbox-short.txt", "r") as filename:\n # Create message_count dictionary\n message_count = {}\n # Create variable for lines of the file\n messages = filename.readlines()\n # Iterate through each message (each line)\n for message in messages:\n # Assign the key to the first (0th) element of the message\n key = message.split()[0]\n # Assign the value to the second element of the message\n value = message.split()[1]\n # Check if key is already in dictionary\n if key not in message_count.keys():\n # if not, add key/value pair to dictionary\n message_count[key] = value\n# Create variable to count emails\nmax_emails = 0\n# Iterate through keys in dictionary\nfor key in message_count.keys():\n # Check if key is larger than the max emails\n if int(message_count[key]) >= max_emails:\n # If so, reassign max_emails to that key\n max_emails = int(message_count[key])\nprint(max_emails)\n","language":"python","errinfo":"IndexError: list index out of range on line 10","to_save":"False","prefix":"","partner":"","course":"CMSC-254-001-F2023","clientLoginStatus":true,"timezoneoffset":4}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions