

Same O(1) performance in either direction. Deques support thread-safe, memoryĮfficient appends and pops from either side of the deque with approximately the If iterable is not specified, the new deque is empty.ĭeques are a generalization of stacks and queues (the name is pronounced “deck”Īnd is short for “double-ended queue”). Returns a new deque object initialized left-to-right (using append()) withĭata from iterable. It ignores zero andĭeque objects ¶ class collections. The elements() method requires integer counts. Support addition, subtraction, and comparison.

There are no type restrictions, but the value type needs to The inputs may be negative or zero, but only outputs with positive valuesĪre created. The multiset methods are designed only for use cases with positive values. Update() and subtract() which allow negative and zero values The most_common() method requires only that the values be orderable.įor in-place operations such as c += 1, the value type need only Representing counts, but you could store anything in the value field.

The Counter class itself is a dictionary subclass with no This section documents the minimum range and type restrictions. Running counts however, care was taken to not unnecessarily preclude useĬases needing other types or negative values. This method is used forĬreating subcontexts that can be updated without altering values in anyĬounters were primarily designed to work with positive integers to represent Specified, an empty dict is used, so that a call to d.new_child() It becomes the new map at the front of the list of mappings if not Returns a new ChainMap containing a new map followed byĪll of the maps in the current instance. The list shouldĪlways contain at least one mapping. It is the only stored state and canīe modified to change which mappings are searched. The list is ordered fromįirst-searched to last-searched. Maps attribute, a method for creating new subcontexts, and a property forĪccessing all but the first mapping: maps ¶Ī user updateable list of mappings. One of the underlying mappings gets updated, those changes will be reflectedĪll of the usual dictionary methods are supported. InĬontrast, writes, updates, and deletions only operate on the first mapping.Ī ChainMap incorporates the underlying mappings by reference. Lookups search the underlying mappings successively until a key is found. That list is public and canīe accessed or updated using the maps attribute. The underlying mappings are stored in a list. If no maps are specified, a single emptyĭictionary is provided so that a new chain always has at least one mapping. ChainMap ( *maps ) ¶Ī ChainMap groups multiple dicts or other mappings together toĬreate a single, updateable view. The class can be used to simulate nested scopes and is useful in templating. It is often much faster than creatingĪ new dictionary and running multiple update() calls. A ChainMap class is provided for quickly linking a number of mappings
