rotate(nrotates all the items steps to the right if is negativeitems are rotated to the left deques are often overlooked by many python programmers howeverthis type offers many advantages firstthe implementation is highly efficient--even to level of using internal data structures that provide good processor cache behavior appending items at the end is only slightly slower than the built-in list typewhereas inserting items at the front is significantly faster operations that add new items to deque are also thread-safemaking this type appropriate for implementing queues deques can also be serialized using the pickle module defaultdict([default_factory] type that is exactly the same as dictionary except for the handling of missing keys when lookup occurs on key that does not yet existthe function supplied as default_factory is called to provide default value which is then saved as the value of the associated key the remaining arguments to defaultdict are exactly the same as the built-in dict(function an instance of defaultdictionary has the same operations as built-in dictionary the attribute default_factory contains the function passed as the first argument and can be modified as necessary defaultdict object is useful if you are trying to use dictionary as container for tracking data for examplesuppose you wanted to keep track of the position of each word in string here is how you could use defaultdict to do this easilyfrom collections import defaultdict "yeah but no but yeah but no but yeahwords split(wordlocations defaultdict(listfor nw in enumerate(words)wordlocations[wappend(nwordlocations defaultdict({'yeah'[ ]'but'[ ]'no'[ ]}in this examplethe lookup wordlocations[wwill "failthe first time word is encountered howeverinstead of raising keyerrorthe function list supplied as default_factory is called to create new value built-in dictionaries have method setdefault(that can be used to achieve similar resultbut it often makes code confusing to read and run slower for examplethe statement that appends new item shown previously could be replaced by wordlocations setdefault( ,[]append(nthis is not nearly as clear and in simple timing testit runs nearly twice as slow as using defaultdict object named tuples tuples are frequently used to represent simple data structures for examplea network address might be represented as tuple addr (hostnameporta common complaint with tuples is that the individual items have to be accessed by numerical index-for exampleaddr[ or addr[ this leads to code that is confusing to read and hard to maintain unless you can remember what all of the index values mean (and the problem gets worse the larger the tuple getsf lib fl ff