Creating new kinds of collections
We'll look at some extensions we might make to Python's built-in container classes. Although, we won't show an example of extending each container. If we did, the book would become out of control in size.
We'll pick an example of extending a specific container and see how the process works:
Define the requirements. This may include research on Wikipedia, generally starting here: http://en.wikipedia.org/wiki/Data_structure. Designs of data structures can be complex because there are often complex edge cases.
If necessary, look at the
collections.abc
module to see what methods must be implemented to create the new functionality.Create some test cases. This also requires careful study of the algorithms to ensure that the edge cases are properly covered.
Code.
We need to emphasize the importance of researching the fundamentals before trying to invent a new kind of data structure. In addition to searching the Web for overviews and summaries, details will be necessary...