Same data, different shapes
You finished Advanced Python, so you already use data structures every day: list, dict, set, tuple. This course is about what happens underneath, and why the shape you pick can make the same program thousands of times faster.
A data structure is a way of arranging data in memory so that certain operations are fast. That is the whole definition. Every structure in this course is a different answer to one question: which operations do you need to be fast?
Here is the idea in one experiment. We store 10,000 usernames two ways: as a list (a row of items) and as a dict (items filed under keys). Then we look up the same user in both and count how much work each shape does.
Code exercise · python
Run this. The list has to check names one by one. The dict jumps straight to the answer (you will learn exactly how in the hash tables unit). Look at the two check counts.
Quiz
A data structure is best described as:
Code exercise · python
Your turn. You have parallel lists of locker codes and room numbers. First find the room for code "G79" by scanning `codes` with a loop, counting checks, then build a dict with `dict(zip(codes, rooms))` and look it up directly. Print in the exact format shown in the expected output.