|
|
|
@@ -22,7 +22,7 @@ __author__ = ('Nicola Larosa <nico-NoSp@m-tekNico.net>,'
|
|
|
|
|
|
|
|
|
|
|
|
__docformat__ = "restructuredtext en"
|
|
|
|
__docformat__ = "restructuredtext en"
|
|
|
|
|
|
|
|
|
|
|
|
__revision__ = '$Id: odict.py 129 2005-09-12 18:15:28Z teknico $'
|
|
|
|
__revision__ = '$Id$'
|
|
|
|
|
|
|
|
|
|
|
|
__version__ = '0.2.2'
|
|
|
|
__version__ = '0.2.2'
|
|
|
|
|
|
|
|
|
|
|
|
@@ -38,40 +38,40 @@ import types, warnings
|
|
|
|
class OrderedDict(dict):
|
|
|
|
class OrderedDict(dict):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
A class of dictionary that keeps the insertion order of keys.
|
|
|
|
A class of dictionary that keeps the insertion order of keys.
|
|
|
|
|
|
|
|
|
|
|
|
All appropriate methods return keys, items, or values in an ordered way.
|
|
|
|
All appropriate methods return keys, items, or values in an ordered way.
|
|
|
|
|
|
|
|
|
|
|
|
All normal dictionary methods are available. Update and comparison is
|
|
|
|
All normal dictionary methods are available. Update and comparison is
|
|
|
|
restricted to other OrderedDict objects.
|
|
|
|
restricted to other OrderedDict objects.
|
|
|
|
|
|
|
|
|
|
|
|
Various sequence methods are available, including the ability to explicitly
|
|
|
|
Various sequence methods are available, including the ability to explicitly
|
|
|
|
mutate the key ordering.
|
|
|
|
mutate the key ordering.
|
|
|
|
|
|
|
|
|
|
|
|
__contains__ tests:
|
|
|
|
__contains__ tests:
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3),))
|
|
|
|
>>> d = OrderedDict(((1, 3),))
|
|
|
|
>>> 1 in d
|
|
|
|
>>> 1 in d
|
|
|
|
1
|
|
|
|
1
|
|
|
|
>>> 4 in d
|
|
|
|
>>> 4 in d
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
|
|
|
|
|
|
|
__getitem__ tests:
|
|
|
|
__getitem__ tests:
|
|
|
|
|
|
|
|
|
|
|
|
>>> OrderedDict(((1, 3), (3, 2), (2, 1)))[2]
|
|
|
|
>>> OrderedDict(((1, 3), (3, 2), (2, 1)))[2]
|
|
|
|
1
|
|
|
|
1
|
|
|
|
>>> OrderedDict(((1, 3), (3, 2), (2, 1)))[4]
|
|
|
|
>>> OrderedDict(((1, 3), (3, 2), (2, 1)))[4]
|
|
|
|
Traceback (most recent call last):
|
|
|
|
Traceback (most recent call last):
|
|
|
|
KeyError: 4
|
|
|
|
KeyError: 4
|
|
|
|
|
|
|
|
|
|
|
|
__len__ tests:
|
|
|
|
__len__ tests:
|
|
|
|
|
|
|
|
|
|
|
|
>>> len(OrderedDict())
|
|
|
|
>>> len(OrderedDict())
|
|
|
|
0
|
|
|
|
0
|
|
|
|
>>> len(OrderedDict(((1, 3), (3, 2), (2, 1))))
|
|
|
|
>>> len(OrderedDict(((1, 3), (3, 2), (2, 1))))
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
|
|
|
|
|
|
|
get tests:
|
|
|
|
get tests:
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.get(1)
|
|
|
|
>>> d.get(1)
|
|
|
|
3
|
|
|
|
3
|
|
|
|
@@ -81,9 +81,9 @@ class OrderedDict(dict):
|
|
|
|
5
|
|
|
|
5
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
OrderedDict([(1, 3), (3, 2), (2, 1)])
|
|
|
|
OrderedDict([(1, 3), (3, 2), (2, 1)])
|
|
|
|
|
|
|
|
|
|
|
|
has_key tests:
|
|
|
|
has_key tests:
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.has_key(1)
|
|
|
|
>>> d.has_key(1)
|
|
|
|
1
|
|
|
|
1
|
|
|
|
@@ -95,11 +95,11 @@ class OrderedDict(dict):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Create a new ordered dictionary. Cannot init from a normal dict,
|
|
|
|
Create a new ordered dictionary. Cannot init from a normal dict,
|
|
|
|
nor from kwargs, since items order is undefined in those cases.
|
|
|
|
nor from kwargs, since items order is undefined in those cases.
|
|
|
|
|
|
|
|
|
|
|
|
If the ``strict`` keyword argument is ``True`` (``False`` is the
|
|
|
|
If the ``strict`` keyword argument is ``True`` (``False`` is the
|
|
|
|
default) then when doing slice assignment - the ``OrderedDict`` you are
|
|
|
|
default) then when doing slice assignment - the ``OrderedDict`` you are
|
|
|
|
assigning from *must not* contain any keys in the remaining dict.
|
|
|
|
assigning from *must not* contain any keys in the remaining dict.
|
|
|
|
|
|
|
|
|
|
|
|
>>> OrderedDict()
|
|
|
|
>>> OrderedDict()
|
|
|
|
OrderedDict([])
|
|
|
|
OrderedDict([])
|
|
|
|
>>> OrderedDict({1: 1})
|
|
|
|
>>> OrderedDict({1: 1})
|
|
|
|
@@ -282,7 +282,7 @@ class OrderedDict(dict):
|
|
|
|
def __repr__(self):
|
|
|
|
def __repr__(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Used for __repr__ and __str__
|
|
|
|
Used for __repr__ and __str__
|
|
|
|
|
|
|
|
|
|
|
|
>>> r1 = repr(OrderedDict((('a', 'b'), ('c', 'd'), ('e', 'f'))))
|
|
|
|
>>> r1 = repr(OrderedDict((('a', 'b'), ('c', 'd'), ('e', 'f'))))
|
|
|
|
>>> r1
|
|
|
|
>>> r1
|
|
|
|
"OrderedDict([('a', 'b'), ('c', 'd'), ('e', 'f')])"
|
|
|
|
"OrderedDict([('a', 'b'), ('c', 'd'), ('e', 'f')])"
|
|
|
|
@@ -320,7 +320,7 @@ class OrderedDict(dict):
|
|
|
|
>>> d[1:3] = OrderedDict(((1, 2), (5, 6), (7, 8)))
|
|
|
|
>>> d[1:3] = OrderedDict(((1, 2), (5, 6), (7, 8)))
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
OrderedDict([(0, 1), (1, 2), (5, 6), (7, 8), (3, 4)])
|
|
|
|
OrderedDict([(0, 1), (1, 2), (5, 6), (7, 8), (3, 4)])
|
|
|
|
|
|
|
|
|
|
|
|
>>> a = OrderedDict(((0, 1), (1, 2), (2, 3)), strict=True)
|
|
|
|
>>> a = OrderedDict(((0, 1), (1, 2), (2, 3)), strict=True)
|
|
|
|
>>> a[3] = 4
|
|
|
|
>>> a[3] = 4
|
|
|
|
>>> a
|
|
|
|
>>> a
|
|
|
|
@@ -344,12 +344,12 @@ class OrderedDict(dict):
|
|
|
|
>>> a[::-1] = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
|
|
|
|
>>> a[::-1] = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
|
|
|
|
>>> a
|
|
|
|
>>> a
|
|
|
|
OrderedDict([(3, 4), (2, 3), (1, 2), (0, 1)])
|
|
|
|
OrderedDict([(3, 4), (2, 3), (1, 2), (0, 1)])
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
|
|
|
|
>>> d = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
|
|
|
|
>>> d[:1] = 3
|
|
|
|
>>> d[:1] = 3
|
|
|
|
Traceback (most recent call last):
|
|
|
|
Traceback (most recent call last):
|
|
|
|
TypeError: slice assignment requires an OrderedDict
|
|
|
|
TypeError: slice assignment requires an OrderedDict
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
|
|
|
|
>>> d = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
|
|
|
|
>>> d[:1] = OrderedDict([(9, 8)])
|
|
|
|
>>> d[:1] = OrderedDict([(9, 8)])
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
@@ -443,7 +443,7 @@ class OrderedDict(dict):
|
|
|
|
def __getattr__(self, name):
|
|
|
|
def __getattr__(self, name):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Implemented so that access to ``sequence`` raises a warning.
|
|
|
|
Implemented so that access to ``sequence`` raises a warning.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict()
|
|
|
|
>>> d = OrderedDict()
|
|
|
|
>>> d.sequence
|
|
|
|
>>> d.sequence
|
|
|
|
[]
|
|
|
|
[]
|
|
|
|
@@ -462,7 +462,7 @@ class OrderedDict(dict):
|
|
|
|
def __deepcopy__(self, memo):
|
|
|
|
def __deepcopy__(self, memo):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
To allow deepcopy to work with OrderedDict.
|
|
|
|
To allow deepcopy to work with OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
>>> from copy import deepcopy
|
|
|
|
>>> from copy import deepcopy
|
|
|
|
>>> a = OrderedDict([(1, 1), (2, 2), (3, 3)])
|
|
|
|
>>> a = OrderedDict([(1, 1), (2, 2), (3, 3)])
|
|
|
|
>>> a['test'] = {}
|
|
|
|
>>> a['test'] = {}
|
|
|
|
@@ -491,7 +491,7 @@ class OrderedDict(dict):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
``items`` returns a list of tuples representing all the
|
|
|
|
``items`` returns a list of tuples representing all the
|
|
|
|
``(key, value)`` pairs in the dictionary.
|
|
|
|
``(key, value)`` pairs in the dictionary.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.items()
|
|
|
|
>>> d.items()
|
|
|
|
[(1, 3), (3, 2), (2, 1)]
|
|
|
|
[(1, 3), (3, 2), (2, 1)]
|
|
|
|
@@ -504,7 +504,7 @@ class OrderedDict(dict):
|
|
|
|
def keys(self):
|
|
|
|
def keys(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Return a list of keys in the ``OrderedDict``.
|
|
|
|
Return a list of keys in the ``OrderedDict``.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.keys()
|
|
|
|
>>> d.keys()
|
|
|
|
[1, 3, 2]
|
|
|
|
[1, 3, 2]
|
|
|
|
@@ -514,10 +514,10 @@ class OrderedDict(dict):
|
|
|
|
def values(self, values=None):
|
|
|
|
def values(self, values=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Return a list of all the values in the OrderedDict.
|
|
|
|
Return a list of all the values in the OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
Optionally you can pass in a list of values, which will replace the
|
|
|
|
Optionally you can pass in a list of values, which will replace the
|
|
|
|
current list. The value list must be the same len as the OrderedDict.
|
|
|
|
current list. The value list must be the same len as the OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.values()
|
|
|
|
>>> d.values()
|
|
|
|
[3, 2, 1]
|
|
|
|
[3, 2, 1]
|
|
|
|
@@ -595,7 +595,7 @@ class OrderedDict(dict):
|
|
|
|
def pop(self, key, *args):
|
|
|
|
def pop(self, key, *args):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
No dict.pop in Python 2.2, gotta reimplement it
|
|
|
|
No dict.pop in Python 2.2, gotta reimplement it
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.pop(3)
|
|
|
|
>>> d.pop(3)
|
|
|
|
2
|
|
|
|
2
|
|
|
|
@@ -627,7 +627,7 @@ class OrderedDict(dict):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Delete and return an item specified by index, not a random one as in
|
|
|
|
Delete and return an item specified by index, not a random one as in
|
|
|
|
dict. The index is -1 by default (the last item).
|
|
|
|
dict. The index is -1 by default (the last item).
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.popitem()
|
|
|
|
>>> d.popitem()
|
|
|
|
(2, 1)
|
|
|
|
(2, 1)
|
|
|
|
@@ -673,7 +673,7 @@ class OrderedDict(dict):
|
|
|
|
def update(self, from_od):
|
|
|
|
def update(self, from_od):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Update from another OrderedDict or sequence of (key, value) pairs
|
|
|
|
Update from another OrderedDict or sequence of (key, value) pairs
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 0), (0, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 0), (0, 1)))
|
|
|
|
>>> d.update(OrderedDict(((1, 3), (3, 2), (2, 1))))
|
|
|
|
>>> d.update(OrderedDict(((1, 3), (3, 2), (2, 1))))
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
@@ -705,11 +705,11 @@ class OrderedDict(dict):
|
|
|
|
def rename(self, old_key, new_key):
|
|
|
|
def rename(self, old_key, new_key):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Rename the key for a given value, without modifying sequence order.
|
|
|
|
Rename the key for a given value, without modifying sequence order.
|
|
|
|
|
|
|
|
|
|
|
|
For the case where new_key already exists this raise an exception,
|
|
|
|
For the case where new_key already exists this raise an exception,
|
|
|
|
since if new_key exists, it is ambiguous as to what happens to the
|
|
|
|
since if new_key exists, it is ambiguous as to what happens to the
|
|
|
|
associated values, and the position of new_key in the sequence.
|
|
|
|
associated values, and the position of new_key in the sequence.
|
|
|
|
|
|
|
|
|
|
|
|
>>> od = OrderedDict()
|
|
|
|
>>> od = OrderedDict()
|
|
|
|
>>> od['a'] = 1
|
|
|
|
>>> od['a'] = 1
|
|
|
|
>>> od['b'] = 2
|
|
|
|
>>> od['b'] = 2
|
|
|
|
@@ -741,10 +741,10 @@ class OrderedDict(dict):
|
|
|
|
def setitems(self, items):
|
|
|
|
def setitems(self, items):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This method allows you to set the items in the dict.
|
|
|
|
This method allows you to set the items in the dict.
|
|
|
|
|
|
|
|
|
|
|
|
It takes a list of tuples - of the same sort returned by the ``items``
|
|
|
|
It takes a list of tuples - of the same sort returned by the ``items``
|
|
|
|
method.
|
|
|
|
method.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict()
|
|
|
|
>>> d = OrderedDict()
|
|
|
|
>>> d.setitems(((3, 1), (2, 3), (1, 2)))
|
|
|
|
>>> d.setitems(((3, 1), (2, 3), (1, 2)))
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
@@ -759,10 +759,10 @@ class OrderedDict(dict):
|
|
|
|
``setkeys`` all ows you to pass in a new list of keys which will
|
|
|
|
``setkeys`` all ows you to pass in a new list of keys which will
|
|
|
|
replace the current set. This must contain the same set of keys, but
|
|
|
|
replace the current set. This must contain the same set of keys, but
|
|
|
|
need not be in the same order.
|
|
|
|
need not be in the same order.
|
|
|
|
|
|
|
|
|
|
|
|
If you pass in new keys that don't match, a ``KeyError`` will be
|
|
|
|
If you pass in new keys that don't match, a ``KeyError`` will be
|
|
|
|
raised.
|
|
|
|
raised.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.keys()
|
|
|
|
>>> d.keys()
|
|
|
|
[1, 3, 2]
|
|
|
|
[1, 3, 2]
|
|
|
|
@@ -790,9 +790,9 @@ class OrderedDict(dict):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
You can pass in a list of values, which will replace the
|
|
|
|
You can pass in a list of values, which will replace the
|
|
|
|
current list. The value list must be the same len as the OrderedDict.
|
|
|
|
current list. The value list must be the same len as the OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
(Or a ``ValueError`` is raised.)
|
|
|
|
(Or a ``ValueError`` is raised.)
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.setvalues((1, 2, 3))
|
|
|
|
>>> d.setvalues((1, 2, 3))
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
@@ -812,7 +812,7 @@ class OrderedDict(dict):
|
|
|
|
def index(self, key):
|
|
|
|
def index(self, key):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Return the position of the specified key in the OrderedDict.
|
|
|
|
Return the position of the specified key in the OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.index(3)
|
|
|
|
>>> d.index(3)
|
|
|
|
1
|
|
|
|
1
|
|
|
|
@@ -825,10 +825,10 @@ class OrderedDict(dict):
|
|
|
|
def insert(self, index, key, value):
|
|
|
|
def insert(self, index, key, value):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Takes ``index``, ``key``, and ``value`` as arguments.
|
|
|
|
Takes ``index``, ``key``, and ``value`` as arguments.
|
|
|
|
|
|
|
|
|
|
|
|
Sets ``key`` to ``value``, so that ``key`` is at position ``index`` in
|
|
|
|
Sets ``key`` to ``value``, so that ``key`` is at position ``index`` in
|
|
|
|
the OrderedDict.
|
|
|
|
the OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.insert(0, 4, 0)
|
|
|
|
>>> d.insert(0, 4, 0)
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
@@ -849,7 +849,7 @@ class OrderedDict(dict):
|
|
|
|
def reverse(self):
|
|
|
|
def reverse(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Reverse the order of the OrderedDict.
|
|
|
|
Reverse the order of the OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
|
|
|
|
>>> d.reverse()
|
|
|
|
>>> d.reverse()
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
@@ -860,10 +860,10 @@ class OrderedDict(dict):
|
|
|
|
def sort(self, *args, **kwargs):
|
|
|
|
def sort(self, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Sort the key order in the OrderedDict.
|
|
|
|
Sort the key order in the OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
This method takes the same arguments as the ``list.sort`` method on
|
|
|
|
This method takes the same arguments as the ``list.sort`` method on
|
|
|
|
your version of Python.
|
|
|
|
your version of Python.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = OrderedDict(((4, 1), (2, 2), (3, 3), (1, 4)))
|
|
|
|
>>> d = OrderedDict(((4, 1), (2, 2), (3, 3), (1, 4)))
|
|
|
|
>>> d.sort()
|
|
|
|
>>> d.sort()
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
@@ -875,7 +875,7 @@ class Keys(object):
|
|
|
|
# FIXME: should this object be a subclass of list?
|
|
|
|
# FIXME: should this object be a subclass of list?
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Custom object for accessing the keys of an OrderedDict.
|
|
|
|
Custom object for accessing the keys of an OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
Can be called like the normal ``OrderedDict.keys`` method, but also
|
|
|
|
Can be called like the normal ``OrderedDict.keys`` method, but also
|
|
|
|
supports indexing and sequence methods.
|
|
|
|
supports indexing and sequence methods.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@@ -896,7 +896,7 @@ class Keys(object):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
You cannot assign to keys, but you can do slice assignment to re-order
|
|
|
|
You cannot assign to keys, but you can do slice assignment to re-order
|
|
|
|
them.
|
|
|
|
them.
|
|
|
|
|
|
|
|
|
|
|
|
You can only do slice assignment if the new set of keys is a reordering
|
|
|
|
You can only do slice assignment if the new set of keys is a reordering
|
|
|
|
of the original set.
|
|
|
|
of the original set.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@@ -966,7 +966,7 @@ class Keys(object):
|
|
|
|
class Items(object):
|
|
|
|
class Items(object):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Custom object for accessing the items of an OrderedDict.
|
|
|
|
Custom object for accessing the items of an OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
Can be called like the normal ``OrderedDict.items`` method, but also
|
|
|
|
Can be called like the normal ``OrderedDict.items`` method, but also
|
|
|
|
supports indexing and sequence methods.
|
|
|
|
supports indexing and sequence methods.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@@ -1076,7 +1076,7 @@ class Items(object):
|
|
|
|
class Values(object):
|
|
|
|
class Values(object):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Custom object for accessing the values of an OrderedDict.
|
|
|
|
Custom object for accessing the values of an OrderedDict.
|
|
|
|
|
|
|
|
|
|
|
|
Can be called like the normal ``OrderedDict.values`` method, but also
|
|
|
|
Can be called like the normal ``OrderedDict.values`` method, but also
|
|
|
|
supports indexing and sequence methods.
|
|
|
|
supports indexing and sequence methods.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@@ -1098,7 +1098,7 @@ class Values(object):
|
|
|
|
def __setitem__(self, index, value):
|
|
|
|
def __setitem__(self, index, value):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Set the value at position i to value.
|
|
|
|
Set the value at position i to value.
|
|
|
|
|
|
|
|
|
|
|
|
You can only do slice assignment to values if you supply a sequence of
|
|
|
|
You can only do slice assignment to values if you supply a sequence of
|
|
|
|
equal length to the slice you are replacing.
|
|
|
|
equal length to the slice you are replacing.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@@ -1167,12 +1167,12 @@ class SequenceOrderedDict(OrderedDict):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Experimental version of OrderedDict that has a custom object for ``keys``,
|
|
|
|
Experimental version of OrderedDict that has a custom object for ``keys``,
|
|
|
|
``values``, and ``items``.
|
|
|
|
``values``, and ``items``.
|
|
|
|
|
|
|
|
|
|
|
|
These are callable sequence objects that work as methods, or can be
|
|
|
|
These are callable sequence objects that work as methods, or can be
|
|
|
|
manipulated directly as sequences.
|
|
|
|
manipulated directly as sequences.
|
|
|
|
|
|
|
|
|
|
|
|
Test for ``keys``, ``items`` and ``values``.
|
|
|
|
Test for ``keys``, ``items`` and ``values``.
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = SequenceOrderedDict(((1, 2), (2, 3), (3, 4)))
|
|
|
|
>>> d = SequenceOrderedDict(((1, 2), (2, 3), (3, 4)))
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
SequenceOrderedDict([(1, 2), (2, 3), (3, 4)])
|
|
|
|
SequenceOrderedDict([(1, 2), (2, 3), (3, 4)])
|
|
|
|
@@ -1292,7 +1292,7 @@ class SequenceOrderedDict(OrderedDict):
|
|
|
|
>>> d.values = (1, 2, 3)
|
|
|
|
>>> d.values = (1, 2, 3)
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
SequenceOrderedDict([(1, 1), (2, 2), (3, 3)])
|
|
|
|
SequenceOrderedDict([(1, 1), (2, 2), (3, 3)])
|
|
|
|
|
|
|
|
|
|
|
|
>>> d = SequenceOrderedDict(((1, 2), (2, 3), (3, 4)))
|
|
|
|
>>> d = SequenceOrderedDict(((1, 2), (2, 3), (3, 4)))
|
|
|
|
>>> d
|
|
|
|
>>> d
|
|
|
|
SequenceOrderedDict([(1, 2), (2, 3), (3, 4)])
|
|
|
|
SequenceOrderedDict([(1, 2), (2, 3), (3, 4)])
|
|
|
|
|