By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Grade 9 Computer Science (ICT) – Python: Data Analysis with Lists and Dicts
"If you had a giant spreadsheet of every student’s test scores, club memberships, and absences in your school, how would you find the average score for just the debate team members—or figure out which club has the highest average GPA? And why can’t you just scroll through it like a text message?" By the end, you’ll know how to turn raw data into answers using Python’s lists and dictionaries, the way a detective turns clues into a case.
Imagine your school’s student records as a giant bulletin board in the principal’s office. Each row is a student, and each column is a piece of data about them: name, grade, GPA, clubs they’re in, and test scores. If you tried to analyze this by hand, you’d go cross-eyed—so Python gives you two tools to organize and search it:
"Debate Team"
Together, these let you filter, group, and calculate data at scale. For instance: 1. Loop through a list of student dictionaries.2. Check if "Debate Team" is in their "clubs" list.3. If yes, add their GPA to a running total and count them.4. Divide the total by the count to get the average.
"clubs"
Key Vocabulary:- List: An ordered, changeable collection of items (like a row in a spreadsheet). Example: test_scores = [88, 92, 78, 95] (a list of math test scores for four students). Note: In college, you’ll learn about linked lists (where items point to each other) and time complexity (how fast operations like sorting take).
test_scores = [88, 92, 78, 95]
Dictionary: A collection of key-value pairs where each key is unique (like a column header mapping to its data). Example: student = {"name": "Jamie", "grade": 10, "clubs": ["Debate", "Robotics"]}. Note: In databases, dictionaries resemble hash tables; in other languages, they’re called maps or associative arrays.
student = {"name": "Jamie", "grade": 10, "clubs": ["Debate", "Robotics"]}
Loop: A way to repeat code for each item in a list or dictionary. Example: for score in test_scores: (runs the indented code below it for every score in the list). Note: In functional programming (college CS), loops are often replaced with higher-order functions like map() and filter().
for score in test_scores:
map()
filter()
Index: The position of an item in a list (starting at 0). Example: In test_scores = [88, 92, 78], test_scores[1] is 92 (the second item). Note: Some languages (like R) use 1-based indexing, which can trip up Python programmers.
test_scores = [88, 92, 78]
test_scores[1]
92
How This Appears on Assessments:- Classroom (Formative): Short coding exercises (e.g., "Write a function to return the average GPA of students in a given club") or debugging tasks (e.g., "Fix this code that’s supposed to count how many students have GPAs above 3.5").- Standardized Tests (e.g., AP CSP, state ICT exams): - Multiple Choice: Questions like "What does students[2]["clubs"] return if students is a list of dictionaries?" with distractors like: - A list of all clubs (wrong—it’s just the clubs for the 3rd student). - A syntax error (wrong—this is valid Python). - The 2nd student’s name (wrong—it’s accessing the "clubs" key, not "name"). - Short Answer: "Explain how you would use a dictionary to count how many students are in each club. Write pseudocode." - Performance Task (AP CSP): A multi-part project where you analyze a dataset (e.g., "Find the club with the highest average GPA") and document your process.
students[2]["clubs"]
students
"name"
Proficient vs. Developing Responses:| Proficient | Developing | |----------------|----------------| | Uses loops and conditionals correctly to filter data (e.g., if "Debate" in student["clubs"]). | Hardcodes values (e.g., checks for "Debate" but not other clubs). | | Handles edge cases (e.g., empty lists, missing keys). | Crashes if a key is missing (e.g., KeyError). | | Explains why a dictionary is better than a list for certain tasks. | Just says "dictionaries are faster" without context. |
if "Debate" in student["clubs"]
"Debate"
KeyError
Model Proficient Response (Short Answer):Prompt: "Write a function average_gpa(club_name) that takes a list of student dictionaries and returns the average GPA of students in the given club. Handle cases where no students are in the club."
average_gpa(club_name)
def average_gpa(students, club_name): total = 0 count = 0 for student in students: if club_name in student["clubs"]: total += student["gpa"] count += 1 if count == 0: return 0 # or return None, depending on requirements return total / count
Why it’s proficient: - Uses a loop to iterate through students.- Checks for club membership with in.- Handles division by zero (edge case).- Returns a meaningful value even if no students are in the club.
in
Mistake 1: Off-by-One Errors in List IndexingPrompt: "Given scores = [85, 90, 78, 92], write code to print the first and last scores." Common Wrong Response:
scores = [85, 90, 78, 92]
print(scores[1], scores[4])
Why It Loses Credit: - scores[1] is the second item (90), not the first.- scores[4] is out of range (lists start at 0; the last index is 3).Correct Approach:
scores[1]
scores[4]
print(scores[0], scores[-1]) # -1 is Python's shortcut for "last item"
Mistake 2: Forgetting to Check for Key ExistencePrompt: "Write code to print the GPA of a student named 'Alex' in the list students." Common Wrong Response:
print(students["Alex"]["gpa"])
Why It Loses Credit: - students is a list of dictionaries, not a dictionary itself. You need to loop through the list first.- Even if students were a dictionary, this assumes "Alex" exists (would crash with KeyError).Correct Approach:
for student in students: if student["name"] == "Alex": print(student["gpa"]) break
Mistake 3: Misusing Dictionaries for Ordered DataPrompt: "Explain whether a list or dictionary is better for storing the order of finishers in a race (1st, 2nd, 3rd)." Common Wrong Response: "A dictionary is better because you can map '1st' to 'Jamie' and '2nd' to 'Taylor'." Why It Loses Credit: - Dictionaries are unordered (in Python <3.7) and don’t guarantee sequence. Lists preserve order.- The student conflates labels (1st, 2nd) with positions (index 0, 1).Correct Approach: "A list is better because the order of finishers matters. You can store ["Jamie", "Taylor", "Riley"] and know finishers[0] is 1st place. A dictionary would lose the sequence."
["Jamie", "Taylor", "Riley"]
finishers[0]
Within CS: Lists/Dicts → Algorithms → Understanding how to loop through and filter data is the foundation for sorting algorithms (e.g., bubble sort vs. quicksort) and search algorithms (e.g., binary search).
Across Subjects: Dictionaries → Biology (Genetics) → A DNA sequence is like a dictionary where keys are gene names (e.g., "BRCA1") and values are nucleotide sequences. Biologists use similar loops to analyze mutations.
"BRCA1"
Outside School: Data Analysis → Fantasy Sports → Fantasy football apps use lists/dicts to track player stats (e.g., {"Tom Brady": [250, 2, 1]} for yards, touchdowns, interceptions). The "average points" feature is just a loop summing values.
{"Tom Brady": [250, 2, 1]}
"If you had a list of 1 million student records, would it be faster to use a list of dictionaries or a dictionary of lists to calculate the average GPA per club? Why?"
Pointer Toward the Answer: - A list of dictionaries (e.g., [{"name": "Jamie", "clubs": ["Debate"], "gpa": 3.8}, ...]) is intuitive but slow for large data because you must loop through every student to check their clubs.- A dictionary of lists (e.g., {"Debate": [3.8, 3.5], "Robotics": [3.9, 4.0]}) lets you jump directly to the club you care about, but building it requires preprocessing the data.- The tradeoff is between time to write the code (list of dicts is easier) and time to run the code (dict of lists is faster). In college, you’ll study Big O notation to quantify this.
[{"name": "Jamie", "clubs": ["Debate"], "gpa": 3.8}, ...]
{"Debate": [3.8, 3.5], "Robotics": [3.9, 4.0]}
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.