Loops and Core Data Structures
This session covers fundamental Python data structures, iteration techniques, and practical loop patterns, using a campus coffee cart sales dataset as a practical working example.
It begins by introducing Python’s four built-in containers, contrasting how ordered lists allow duplicates and in-place modifications, tuples store fixed records that cannot be changed, sets keep only distinct values for membership testing with in and not in, and dictionaries map unique keys to values. The material covers essential methods including indexing, slicing, list comprehensions, tuple unpacking, and using .get() to prevent lookup errors.
The session also explores looping mechanisms, examining for loops over sequences, ranges, and enumerated items, alongside condition- and sentinel-controlled while loops. Finally, it establishes four fundamental loop patterns—counting matches, accumulating running totals, filtering items into new lists, and finding maximum or minimum values—as well as techniques for counting item popularity using dictionaries and collections.Counter.

Listen
| Speaker | Text |
|---|---|
| Alex | This is the brief on session 3, loops and data structures. Welcome to session 3. Today, we’re moving way beyond basic Python variables and announcing your next big step, learning how to actually store, organize and analyze real-world data sets. First, to organize all that data, you got to know Python’s 4 core containers. Honestly, think of them like everyday organizers. A list is kind of like your growing grocery receipt, ordered and totally changeable. A tupple though is a fixed business address. Absolutely no changing that one. A set is basically a VIP list for unique values only. And your dictionary, that’s just your contacts app, letting you quickly look up stuff by a specific key. Second, once your data is perfectly organized, we need a way to process it using 4 and while loops. You’ll use a 4 loop when you know your collection’s exact size. But what if you don’t? You might wonder, why even risk a program crashing infinite loop with a while statement. Well, it comes down to a sentinel. It’s a specific stop sign value, like a user simply typing quit, that tells the loop to finally power down. Finally, here’s the ultimate cheat code. Almost every complex analysis boils down to just 4 loop patterns, counting, accumulating, filtering, and finding a max. Think of these like a super simple 3-step recipe. Initialize your variable before the loop, update it inside, and use the result after. Get ready because you’re going to apply these exact patterns to a brand new data set in homework too. Master these core containers and those 4 loop patterns, and you’ll have the fundamental blueprint to automate almost any data analysis task in Python. |
Read
Hands-on
Notebooks in 03-Loops-Data-Structures
Special CLI Commands
Use the following CLI commands on the Analytics Research Cluster
| Command | What it does |
|---|---|
ifi8410-status | Checks everything and tells you where you stand. Start here. |
ifi8410-update | Brings in new files from your instructor. |
ifi8410-test | Saves your work and runs the automatic tests on it. |
ifi8410-submit | Says “this is the version I want graded”. |
Read the document IFI-8410 Course Tools