You've learned about abstract data structures, and you also read that you probably shouldn't build your own abstract data structures using Python classes as you did in the previous section if you're planning to use them in your code.
Benefits of Using Python Data Structures
There are several reasons why you might want to use idiomatic built-in data structures in Python rather than building your own:
Efficiency
Python's built-in data structures are optimized for performance and are generally more efficient than custom implementations. They are implemented in C, a lower-level language than Python, so they can execute faster than equivalent Python code.
Code Simplicity
Using Python's built-in data structures can make your code simpler and easier to read. You don't have to worry about implementing the underlying details of the data structure; you can just use the high-level interface provided by the built-in data structure.
Tested and Reliable
Python's built-in data structures have been thoroughly tested and are known to be reliable. Countless developers have used them in a variety of applications, so you can trust that they are robust and well-designed.
Standard Library
Python's built-in data structures are part of the standard library, so they are available in every Python environment, and you don't have to worry about installing any additional libraries or dependencies.
Does that bring you back to using only lists and dictionaries in your code? Not quite! Python comes with a lot of built-in additional data structures. You'll learn about some of the most useful of them in this section.
The more data structures you know about and understand, the more likely you'll be to pick the right tool for the job. If you only know about a Python list, then you'll attempt to solve every task using a list. Python lists are indeed quite flexible, so you might get quite far doing just that.
When to Use Built-in Data Structures
However, that doesn't mean that a list is always the best tool for the job. You can probably use a wrench to drive a nail into a piece of wood, but arguably, a hammer would be a more fitting tool for that job:
The more data structures you know, the better you'll be at picking the right tool for the job!
Overall, using the right built-in data structures can save you time, improve the efficiency and reliability of your code, and make your code easier to understand and maintain.
In the next lesson, you'll start by learning how you could actually use a list to build the functionality of some of the abstract data structures that you built earlier on. After that, you'll get to know other built-in data structures that do a much better job at it!
Summary: Idiomatic Python Data Structures
- It is not always best to build your own Python data structure
- The more data structures you know, the better you can choose the best option
Benefits of Using Python Data Structures
- Efficiency
- Code simplicity
- Tested and reliable
- Standard library