Each run starts with fresh data. Download any exported files before another run. Your written answers and code drafts are saved on this device; export your work to keep a backup.
M02C01 · Explore · predict · practice
A list has positions
A list stores values in order. Positions start at 0, so names[1] is the second value. A slice such as [0:2] includes positions 0 and 1 but excludes position 2. A negative position counts back from the end.
The slice returns Bilal and Chloe. append() adds a value at the end, so the full list now has five names.
Compare your explanations
Read. They create a list containing four text values in order.
Predict. Dana, then ["Amira", "Bilal"].
Explain. The start position is included, but the stop position 2 is excluded.
One quick check
Which expression selects the second value?
What you should be able to explain. I can predict list positions and slices.
M02C02 · Explore · predict · practice
A dictionary of lists describes columns
Now each dictionary value is a list. The keys describe future column names, and values at the same position belong to the same student. data["Age"] chooses a list; the second pair of brackets chooses an item inside that list.
The age list becomes [20, 21, 20]. Updating one nested list position does not change the other positions.
Compare your explanations
Read. data is a dictionary. data["Age"] is a list.
Predict. Bilal, age 21, at Dubai.
Explain. Names could become paired with another student's age and campus. The lists must stay aligned by position.
One quick check
What does data["Age"][1] select?
What you should be able to explain. I can read a value from a dictionary containing lists.
M02C03 · Explore · predict · practice
A list of dictionaries describes rows
A second arrangement stores one dictionary per student inside a list. Each dictionary is a record, or row. rows[1] selects the second record; ["Name"] then selects a field within it. Both arrangements can later become a pandas DataFrame.
Dana is the last record and there are four records. This arrangement keeps each student's fields together.
Compare your explanations
Read. One dictionary describing one student record.
Predict. Bilal.
Explain. rows is organized as a list of records, so select the record first. data was organized as named columns, so select the column first.
One quick check
Which arrangement stores one dictionary per row?
What you should be able to explain. I can tell column-oriented data from row-oriented records.
M02C04 · Explore · predict · practice
Check lengths before making a table
A rectangular table needs the same number of values in each plain list column. len() counts the values in a list. You can inspect all column lengths before constructing the DataFrame. A missing measurement still needs a position, often filled with None.
Read the example
data = {
"Name": ["Amira", "Bilal", "Chloe"],
"Age": [20, 21, 19]
}
lengths = {"Name": len(data["Name"]), "Age": len(data["Age"])}
same_length = lengths["Name"] == lengths["Age"]
print(lengths)
print("Ready for a rectangular table:", same_length)
Verified example output · pandas 2.2.3
{'Name': 3, 'Age': 3}
Ready for a rectangular table: True
Watch for this. None is a missing-value marker here; "None" in quotes is ordinary text.
Your turn
Add Dana to the Name list. Her age is unknown, so append None to Age. Confirm that the two lengths still match.
For the code check, keep these result variable names: data, same_length. Different valid approaches are welcome.
Show a hint
Append one value to each list; use None without quotes.