Fatskills
Practice. Master. Repeat.
Study Guide: Computer Science - ICT Grade 9 Python Data Analysis with Lists and Dicts
Source: https://www.fatskills.com/9th-grade-science/chapter/computer-science-ict-grade-9-python-data-analysis-with-lists-and-dicts

Computer Science - ICT Grade 9 Python Data Analysis with Lists and Dicts

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~6 min read

Grade 9 Computer Science (ICT) – Python: Data Analysis with Lists and Dicts


1. The Driving Question

"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.


2. The Core Idea – Built, Not Listed

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:


  • Lists are like stacks of sticky notes where each note has the same type of info (e.g., all GPAs in order). You can sort them, add to them, or pull out the 3rd or 100th item without counting by hand.
  • Dictionaries are like labeled folders where each folder has a name (the key) and holds specific data (the value). For example, the key "Debate Team" could map to a list of all debate team members’ GPAs.

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.

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).


  • 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.

  • 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().

  • 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.


3. Assessment Translation

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.

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. |

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."


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.


4. Mistake Taxonomy

Mistake 1: Off-by-One Errors in List Indexing
Prompt: "Given scores = [85, 90, 78, 92], write code to print the first and last scores." Common Wrong Response:


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:


print(scores[0], scores[-1])  # -1 is Python's shortcut for "last item"

Mistake 2: Forgetting to Check for Key Existence
Prompt: "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 Data
Prompt: "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."


5. Connection Layer

  1. 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).

  2. 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.

  3. 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.


6. The Stretch Question

"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.



ADVERTISEMENT