

💻 Week 02 Lab
Collections & API Basics - Problem-First Practice
By the end of this lab, you should be able to: i) Discover and explore unknown data structures using Python methods, ii) Navigate nested dictionaries using chained bracket notation, iii) Recognise when hardcoded approaches need loops (instructor demonstration), iv) Connect bracket notation to the DataFrames you used in Week 01.
This lab builds directly on the 📝 W02 Practice and the 🖥️ W02 Lecture. If you skipped or missed those, you might feel a bit lost. Inform your class teacher so he can instruct you on how to catch up.
📋 Preparation
- Complete the 📝 W02 Practice (DataQuest lessons)
- Make sure you have your notes ready and easy to access!
- Avoid using AI chatbots to give you the answers straight away. It will only harm your learning.
- Review the concepts from the 🖥️ W02 Lecture
- Ensure you can access Nuvolos and launch VS Code:
Using Nuvolos
🛣️ Lab Roadmap
Part | Activity Type | Focus | Time | Outcome |
---|---|---|---|---|
Part I | 🗣️ TEACHING MOMENT | Setup Notebook | 10 min | Create professional lab notebook |
Part II | 🔍 INVESTIGATION | Explore New Data | 20 min | Discover structure without documentation |
Part III | 🗣️ TEACHING MOMENT | Fix Disconnected Data | 25 min | Recognise when loops eliminate repetition |
Part IV | 🎯 ACTION POINTS | Navigate Real API Data | 30 min | Connect to DataFrames from Week 01 |
👉 NOTE: Whenever you see a 🗣️ TEACHING MOMENT, this means your class teacher deserves your full attention!
Part I: Setup Your Notebook (10 min)
Note to class teachers: Welcome students and inform them that this lab has three key exercises. Don’t assume everyone has mastered the Nuvolos and VS Code interface already. It might still take a while to familiarise themselves with the interface. Keep this phase quick. You can help latecomers or those who are struggling once you have completed the first part of the lab.
Your class teacher will demonstrate how to create a notebook file from scratch and set up the first cells.
Follow along with your class teacher as they demonstrate:
Open VS Code. Your teacher will show you how to access
Nuvolos, locate the
Applications tab on the left and click on the
VS Code application.
Create a new Jupyter Notebook. Watch as your teacher right-clicks on the
week02/
folder and selects “New File”. The filename will be:W02-NB02-Practice-Python-Collections.ipynb
Try to do this at the same time as your teacher. If you fall behind, raise your hand and your class teacher will assist you.
Add a professional header. Your teacher will demonstrate how to add a professional header to the notebook:
- Make sure the first cell is a Markdown cell
- Copy the template below into that cell
- Customise it with today’s date and location
- Make sure the first cell communicates the purpose of the notebook
A template you can copy and paste
# 💻 Week 02 Lab – Collections & API Basics
**LSE DS105A – Data for Data Science (2025/26)**
<div style="font-family: system-ui; padding: 20px 30px 20px 20px; background-color: #FFFFFF; border-left: 8px solid #47315E; border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);max-width:600px">
**Today's Lab Session**- 📅 [Add date here]
- ⏰ Check your class group time in your timetable
- 📍 [Add location here]
🥅 **Learning Goals**
What I've learned in this lab:
1.
2.
3.
</div>
Test your setup. Your teacher will add a new code cell and run this to make sure everything works:
print("Hello from Week 02 Lab!")
If you see the message printed below the cell, you’re ready to go!
Finished PART I early? Here’s an extra challenge for you…
Add a table of contents to your notebook using a Markdown numbered list. Create section links and add estimated completion times for each part.
Part II: Explore New Data (20 min)
Note to class teachers: You can choose to split the class as you wish. It’s fine, even encouraged, for students to work in pairs or small groups for the rest of the lab. At the end of this Part II, invoke a brief 🗣️ TEACHING MOMENT (2-3 minutes) to discuss common discoveries and the importance of exploration methods like
.keys()
andtype()
. Share solutions snippets with your class in the dedicated Slack channel in whatever format you prefer.
🎯 ACTION POINTS
- Add a new section in your notebook with the header
## Part II: Explore New Data
, then create a code cell below it and add this mysterious data structure there:
Click here to copy the data
= {
weather_station "station_id": "LSE_MAIN",
"active": True,
"location": {
"city": "London",
"latitude": 51.5085,
"longitude": -0.1257
},"current": {
"temperature": 18,
"humidity": 65,
"conditions": "cloudy",
"wind_speed": 12
},"recent_readings": [12, 15, 14, 18, 16],
"alerts": [],
"last_updated": "2025-10-17T14:30:00"
}
🤔 Think about it: The variable weather_station
is a dictionary. You can use the .keys()
method to see what keys are in the dictionary. What else can you do with a dictionary? The W02-NB01
notebook you created as part of the 📝 W02 Practice should be a good reference for you.
Discover what’s in the data
Pretend you can’t see the code above. Write Python code to find out:
- What is the station ID?
- What is the city name?
- What is the current temperature?
- What is the first reading from
recent_readings
? - What is the last reading from
recent_readings
?
Add separate code cells for each question.
💡 Remember from the 🖥️ W02 Lecture
Always use
type()
to check what kind of data structure you’re working with.Try
type(weather_station)
, thentype(weather_station["location"])
, thentype(weather_station["recent_readings"])
. This should help you know if you are working with a dictionary or a list.Once you know what you are working with, you can use the
len()
or the.keys()
method to see what is inside.
Use your DataQuest notes to help you. Resist the temptation to use AI to get the answers straight away!
Test what breaks.
Try running these two pieces of code:
# Test 1 print(weather_station["city"])
# Test 2 print(len(weather_station["alerts"]))
- What happens with Test 1? Why doesn’t it work?
- What happens with Test 2? What does it tell you about the
alerts
list?
Add Markdown cell(s) with your answers.
Finished PART II early? Here’s an extra challenge for you…
This is for the advanced students.
Here’s a more complex weather monitoring system:
= {
weather_regions "regions": {
"london": {"temp": 18, "air_quality": "good"},
"manchester": {"temp": 15, "air_quality": "moderate"},
"birmingham": {"temp": 17, "air_quality": "good"}
},"daily_readings": [12, 15, 18, 22, 19]
}
Produce a single list, extracted from the data above, that contains the three city names.
Before moving on, your class teacher will gather your thoughts on this exercise, solve any issues you might have and then they will ask you to consider the following scenario:
Why not just store the data in individual variables like this?
= "LSE_MAIN"
station_id = True
active = "London"
city = 18
temperature = 12
recent_1 = 15
recent_2 = 14
recent_3 # ... and so on
Part III: Working with Parallel Lists (25 min)
Note to class teachers: This exercise deliberately leads students to write hardcoded repetition. Let them experience it first, then use the last 5 min to check if they have spotted it as a problem and introduce them to
for
loops. It will be the first time that coding beginners will encounter loops. Share your loop solution in Slack afterwards.
You received some new weather data which this time is in a different format. Instead of being inside a dictionary, the data is now in three separate lists.
🎯 ACTION POINTS
- Create a new section
## Part III: Working with Parallel Lists
and add this code:
Click here to copy the data
= ["06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00",
times "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00"]
= [12, 13, 15, 18, 20, 21, 22, 23, 22, 21, 19, 18, 16, 14, 13]
temps = ["cloudy", "cloudy", "partly cloudy", "sunny", "sunny",
conditions "sunny", "sunny", "sunny", "sunny", "partly cloudy",
"partly cloudy", "cloudy", "rainy", "rainy", "cloudy"]
Print a weather report for noon. Your output should look like this:
At 12:00, the temperature was 22°C and conditions were sunny
The catch, though, is that you can’t just type
print("At 12:00, the temperature was 22°C and conditions were sunny")
into your code but instead you should collect the data from the lists and then print it out.💡 Refer to your DataQuest notes on string formatting and lists to help you!
Create a weather table. Print all 15 observations like this:
06:00 | 12°C | cloudy 07:00 | 13°C | cloudy 08:00 | 15°C | partly cloudy ... 18:00 | 16°C | rainy 19:00 | 14°C | rainy 20:00 | 13°C | cloudy
Create the table using separate print statements (yes, this will feel repetitive and it’s intentional for this exercise!).
Test what happens when things break. Run this code:
12) temps.append(print(f"Time at position 15: {times[15]}")
What error do you get? Why did adding a temperature cause this problem?
Finished PART III early? Here’s an extra challenge for you…
You have rainfall data too:
= [2.1, 0.0, 1.5, 0.0, 0.3, 0.0, 0.8, 1.2, 3.4, 2.0, 1.1, 0.5, 4.2, 2.8, 1.0] rainfall
Create a weather report that includes rainfall: “At 12:00, the temperature was 22°C, conditions were sunny, with 0.8mm of rain”
Your class teacher will now demonstrate a better way to handle this repetitive code.
The table code you wrote is “hardcoded”. You manually wrote code for each case. You just wrote 15 print statements! Imagine if you had 100 observations, or 1000.
You’ll learn to write loops yourself in W03. For now, just observe how they eliminate repetition.
Appendix | Resources, links, etc.
Useful Links
Looking Ahead
- Next week (W03): JSON normalisation and Git basics
- W03 Practice:
for
loops andif-else
conditionals (DataQuest) - Key transition: From messy API data to clean pandas DataFrames
The progression: - Week 01: Worked with clean CSV files and DataFrames - Week 02: Learned how to access nested data structures - Week 03: Will learn how to clean messy data into table format
Support this week
- Slack: Post questions to
#help
- Office Hours: Book via StudentHub
- DataQuest: Review your W02 Practice notes for bracket notation reminders