![]() ![]() To run these yourself, use ``cyordereddict.benchmark()`` ![]() ``update`` ``ordereddict.update(dict_data)`` 6.5 ``update`` ``ordereddict.update(dict_data)`` 5.5 The Python standard library's ``OrderedDict`` ported to Cython. > Point = namedtuple('Point', ) > Point._doc_ # docstring for the new class 'Point(x, y)' > p = Point(11, y=22) # instantiate with positional args or keywords > p + p # indexable like a plain tuple 33 > x, y = p # unpack like a regular tuple > x, y (11, 22) > p.x + p.y # fields also accessible by name 33 > d = p._asdict() # convert to a dictionary > d 11 > Point(**d) # convert from a dictionary Point(x=11, y=22) > p._replace(x=100) # _replace() is like str.**This library is obsolete!** Python 3.5's ``collections.OrderedDict`` was `rewritten in C`_, and is now significantly faster than ``cyordereddict.OrderedDict`` for almost all operations. _map = ') ''' def namedtuple ( typename, field_names, verbose = False, rename = False ): """Returns a new subclass of tuple with named fields. _root = root = # sentinel node root = self. ''' if not args : raise TypeError ( "descriptor '_init_' of 'OrderedDict' object " "needs an argument" ) self = args args = args if len ( args ) > 1 : raise TypeError ( 'expected at most 1 arguments, got %d ' % len ( args )) try : self. The signature is the same as regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary. ![]() def _init_ ( * args, ** kwds ): '''Initialize an ordered dictionary. # Each link is stored as a list of length three. # The sentinel element never gets deleted (this simplifies the algorithm). # The circular doubly linked list starts and ends with a sentinel element. # The internal self._map dict maps keys to links in a doubly linked list. # Big-O running times for all methods are the same as regular dictionaries. # The inherited dict provides _getitem_, _len_, _contains_, and get. _all_ from _collections import deque, defaultdict from operator import itemgetter as _itemgetter, eq as _eq from keyword import iskeyword as _iskeyword import sys as _sys import heapq as _heapq from itertools import repeat as _repeat, chain as _chain, starmap as _starmap from itertools import imap as _imap try : from thread import get_ident as _get_ident except ImportError : from dummy_thread import get_ident as _get_ident # OrderedDict # class OrderedDict ( dict ): 'Dictionary that remembers insertion order' # An inherited dict maps keys to values. from _abcoll import * import _abcoll _all_ += _abcoll. # They should however be considered an integral part of collections.py. ![]() * namedtuple factory function for creating tuple subclasses with named fields * deque list-like container with fast appends and pops on either end * Counter dict subclass for counting hashable objects * OrderedDict dict subclass that remembers the order entries were added * defaultdict dict subclass that calls a factory function to supply missing values ''' _all_ = # For bootstrapping reasons, the collection ABCs are defined in _abcoll.py. '''This module implements specialized container datatypes providing alternatives to Python's general purpose built-in containers, dict, list, set, and tuple. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |