collection

This module contains additional specialized data structures


namedtuple - It returns a tuple with a named entry, which means there will be a name assigned to each value in the tuple. It overcomes the problem of accessing the elements using the index values. With namedtuple( ) it becomes easier to access these values since you do not have to remember the index values to get specific elements.


deque - deque pronounced as 'deck' is an optimized list to perform insertion and deletion easily.


Chainmap - It is a dictionary-like class which is able to make a single view of multiple mappings. It basically returns a list of several other dictionaries. Suppose you have two dictionaries with several key-value pairs, in this case, ChainMap will make a single list with both the dictionaries in it.


Counter - It is a dictionary subclass which is used to count hashable objects.


OrderedDict - It is a dictionary subclass which remembers the order in which the entries were added. Basically, even if you change the value of the key, the position will not be changed because of the order in which it was inserted in the dictionary.


defaultdict - It is a dictionary subclass which calls a factory function to supply missing values. In general, it does not throw any errors when a missing key value is called in a dictionary.


UserDict - This class acts as a wrapper around dictionary objects. The need for this class came from the necessity to subclass directly from dict. It becomes easier to work with this class as the underlying dictionary becomes an attribute.


UserList - This class acts like a wrapper around the list-objects. It is a useful base class for other lists like classes which can inherit from them and override the existing methods or even add fewer new ones as well.


UserString





© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext