Third party data structures
Key 3: Using third-party data structures.
Python has a good bunch of data structures in the core language/library. But sometimes, an application has very specific requirements. We can always use third-party data-structure packages. Most of such modules are Python wrapper over C, C++ implementations:
- The
blist
module provides a drop-in replacement for list,sortedList
, andsortedset
. It is discussed in greater detail in later chapters. - The
bintrees
module provides binary, AVL tree, and Red-Black trees. - The
banyan
module provides Red-Black trees, splay tree, and sorted lists. - The
Sortedcontainers
module providesSortedList
,SortedDict
, andSortedSet
. So, one can get almost every data structure for Python easily. More stress should be given on why one data structure is better than another for a use case.
Arrays/List
For numeric calculations involving math, NumPy arrays should be considered. They are fast, memory-efficient, and provide many vector and matrix operations...