data structuresalgorithmsand code simplification collections the collections module contains high-performance implementations of few useful container typesabstract base classes for various kinds of containersand utility function for creating name-tuple objects each is described in the sections that follow deque and defaultdict two new containers are defined in the collections moduledeque and defaultdict deque([iterable [maxlen]]type representing double-ended queue (dequepronounced "deck"object iterable is an iterable object used to populate the deque deque allows items to be inserted or removed from either end of the queue the implementation has been optimized so that the performance of these operations is approximately the same as ( ( )this is slightly different from list where operations at the front of the list may require shifting of all the elements that follow if the optional maxlen argument is suppliedthe resulting deque object becomes circular buffer of that size that isif new items are addedbut there is no more spaceitems are deleted from the opposite end to make room an instancedof deque has the following methodsd append(xadds to the right side of appendleft(xadds to the left side of clear(removes all items from extend(iterableextends by adding all the items in iterable on the right extendleft(iterableextends by adding all the items in iterable on the left due to the sequence of left appends that occuritems in iterable will appear in reverse order in pop(returns and removes an item from the right side of raises indexerror if is empty popleft(returns and removes an item from the left side of raises indexerror if is empty remove(itemremoves the first occurrence of item raises valueerror if no match is found lib fl ff