课程 · 12 · 07 / 12
Working with Data Structures
Learn advanced operations on lists, dictionaries, and sets. Includes sorting, filtering, and transforming data.
TIPLearning Objectives: After this lesson, you'll master advanced operations on lists, dictionaries, and sets, learn to combine different data structures effectively, and implement common algorithms for sorting, filtering, and transforming data.
Combining Data Structures
Real-world data often requires combining different data structures. Let's explore powerful patterns for working with complex data:
Advanced List Operations
Sorting Algorithms Visualization
Let's implement and visualize a simple sorting algorithm:
Advanced Dictionary Operations
Data Transformation Patterns
Working with Multiple Data Structures
Algorithm Implementation Practice
Practice Exercises
Exercise 1: Data Analysis Pipeline
Exercise 2: Social Network Analysis
Key Takeaways
✅ Complex data structures combine lists, dictionaries, and sets for real-world problems
✅ Sorting and filtering are fundamental operations for data processing
✅ Algorithm implementation helps understand computational thinking
✅ Data transformation converts raw data into useful structures
✅ Performance matters - choose the right data structure for the task
✅ Search algorithms like binary search provide efficient data retrieval
✅ Pattern recognition helps identify common data processing needs
✅ Nested structures enable modeling of complex relationships
Next Steps
In the next lesson, we'll learn about functions - how to create reusable code blocks, understand parameters and return values, and explore scope concepts that make your code more organized and maintainable.
Ready to make your code more organized and reusable? The next lesson will teach you the power of functions!
Further Reading
Visualize It
- Python Tutor — for nested structures (list-of-dicts, dict-of-lists), Python Tutor draws the reference graph so you stop guessing where shared mutations come from.
- VisuAlgo — Sorting & Searching — animated walkthroughs of the algorithms behind
sorted(),bisect, andin.
Official Docs
- Python —
sorted()and HOWTO Sort — the official "Sorting HOW TO" withkey=and stable-sort tricks. - Python —
collectionsmodule —Counter,defaultdict,deque,namedtuple,ChainMap. Each is a power tool. - Python —
itertools&functools— for combining, transforming, reducing.
Tutorials
- Trey Hunner — Iterating in Python — and his entire iteration series.
- Real Python — Idiomatic Python — the patterns that separate beginners from intermediates.
Books
- Book: Fluent Python — Part II ("Data Structures"). The canonical reference.
- Book: Effective Python — Items 13–25 cover comprehensions, generators, dict tricks, and class-based abstractions.