Data Structures
A data structure is a way of organizing values together so programs can store, retrieve, and process them efficiently. Three of the most common are lists, dictionaries, and sets. A list (also called an array in many languages) holds an ordered sequence of values, accessed by position. A dictionary (also called a hash map or object) maps keys to values, like a real dictionary maps words to definitions. A set holds an unordered collection of unique values, useful when you need to check membership without duplicates. Each has different performance characteristics for different operations.
Some examples in Python. A list of names: names = ["Alice", "Bob", "Charlie"]. To access the first name: names[0] returns "Alice". To add a name: names.append("Diana"). A dictionary mapping students to scores: scores = {"Alice": 90, "Bob": 85}. To get Alice score: scores["Alice"] returns 90. To check whether someone is in the dictionary: "Charlie" in scores returns False. A set of unique colors: colors = {"red", "blue", "green"}. Sets automatically remove duplicates and let you do fast membership tests.
Which data structure is best when you need to look up a value by a unique key like a name?
Beyond the basics, more advanced data structures support specialized needs. Trees organize hierarchical data (file systems, organizational charts). Graphs model networks of connections (social networks, road maps). Queues and stacks handle ordered processing in different ways. Hash tables (which underlie dictionaries) provide constant-time lookup. Algorithms (the second half of the classic computer science curriculum) often combine clever data structures with smart procedures to solve problems efficiently. For most everyday programming, lists and dictionaries handle 90 percent of what you need.
Inventory Tracker
Write a small program that tracks an inventory of items in a store. Use a dictionary mapping item names to quantities. Implement three operations: add an item (or increase its quantity), remove some quantity (without going below zero), and print the current inventory. Test it with several operations. The exercise pulls together variables, control flow, functions, and data structures in a small but realistic context.
Data structures are how programs handle real-world data. Once you can choose the right structure for the job, your programs become both faster and easier to understand. Combined with control flow and functions, you now have the core tools to build real programs. From here, you can specialize: web development, data analysis, machine learning, embedded systems, game development, mobile apps, and more. The fundamentals you have learned will transfer to all of them.
Want to keep learning?
Sign up for free to access the full curriculum — all subjects, all ages.
Start Learning Free