deques in the python collections module an implementation of deque class is available in python' standard collections module summary of the most commonly used behaviors of the collections deque class is given in table it uses more asymmetric nomenclature than our adt our deque adt len(dd add firstd add lastd delete firstd delete lastd firstd lastcollections deque len(dd appendleftd appendd popleftd popd[ [- [jd[jval cleard rotate(kd remove(ed count(edescription number of elements add to beginning add to end remove from beginning remove from end access first element access last element access arbitrary entry by index modify arbitrary entry by index clear all contents circularly shift rightward steps remove first matching element count number of matches for table comparison of our deque adt and the collections deque class the collections deque interface was chosen to be consistent with established naming conventions of python' list classfor which append and pop are presumed to act at the end of the list thereforeappendleft and popleft designate an operation at the beginning of the list the library deque also mimics list in that it is an indexed sequenceallowing arbitrary access or modification using the [jsyntax the library deque constructor also supports an optional maxlen parameter to force fixed-length deque howeverif call to append at either end is invoked when the deque is fullit does not throw an errorinsteadit causes one element to be dropped from the opposite side that iscalling appendleft when the deque is full causes an implicit pop from the right side to make room for the new element the current python distribution implements collections deque with hybrid approach that uses aspects of circular arraysbut organized into blocks that are themselves organized in doubly linked list ( data structure that we will introduce in the next the deque class is formally documented to guarantee ( )-time operations at either endbut ( )-time worst-case operations when using index notation near the middle of the deque