Core collections
Before we can look at the more advanced combined collections later in this chapter, you need to understand the workings of the core Python collections. This is not just about their usage; it is also about the time complexities involved, which can strongly affect how your application will behave as it grows. If you are well versed in the time complexities of these objects and know the possibilities of Python 3’s tuple packing and unpacking by heart, then feel free to jump to the Advanced collections section.
list – A mutable list of items
The list
is most likely the container structure that you’ve used most in Python. It is simple in terms of its usage, and for most cases, it exhibits great performance.
While you may already be very familiar with the usage of list
, you might not be aware of the time complexities of the list
object. Luckily, many of the time complexities of list
are very low; append
, get operations, set operations, and...