Python collections.OrderedDict.values() Examples
The following are 30
code examples of collections.OrderedDict.values().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
collections.OrderedDict
, or try the search function
.
Example #1
Source File: odict.py From vulscan with MIT License | 6 votes |
def setvalues(self, values): """ 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. (Or a ``ValueError`` is raised.) >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) >>> d.setvalues((1, 2, 3)) >>> d OrderedDict([(1, 1), (3, 2), (2, 3)]) >>> d.setvalues([6]) Traceback (most recent call last): ValueError: Value list is not the same length as the OrderedDict. """ if len(values) != len(self): # FIXME: correct error to raise? raise ValueError('Value list is not the same length as the ' 'OrderedDict.') self.update(zip(self, values)) ### Sequence Methods ###
Example #2
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def setvalues(self, values): """ 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. (Or a ``ValueError`` is raised.) >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) >>> d.setvalues((1, 2, 3)) >>> d OrderedDict([(1, 1), (3, 2), (2, 3)]) >>> d.setvalues([6]) Traceback (most recent call last): ValueError: Value list is not the same length as the OrderedDict. """ if len(values) != len(self): # FIXME: correct error to raise? raise ValueError('Value list is not the same length as the ' 'OrderedDict.') self.update(zip(self, values)) ### Sequence Methods ###
Example #3
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def __setitem__(self, index, value): """ Set the value at position i to value. You can only do slice assignment to values if you supply a sequence of equal length to the slice you are replacing. """ if isinstance(index, types.SliceType): keys = self._main._sequence[index] if len(keys) != len(value): raise ValueError('attempt to assign sequence of size %s ' 'to slice of size %s' % (len(name), len(keys))) # FIXME: efficiency? Would be better to calculate the indexes # directly from the slice object # NOTE: the new keys can collide with existing keys (or even # contain duplicates) - these will overwrite for key, val in zip(keys, value): self._main[key] = val else: self._main[self._main._sequence[index]] = value ### following methods pinched from UserList and adapted ###
Example #4
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def items(self): """ ``items`` returns a list of tuples representing all the ``(key, value)`` pairs in the dictionary. >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) >>> d.items() [(1, 3), (3, 2), (2, 1)] >>> d.clear() >>> d.items() [] """ return zip(self._sequence, self.values())
Example #5
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __mul__(self, n): return self._main.values()*n
Example #6
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def extend(self, other): raise TypeError('Can\'t extend values')
Example #7
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __init__(self, init_val=(), strict=True): OrderedDict.__init__(self, init_val, strict=strict) self._keys = self.keys self._values = self.values self._items = self.items self.keys = Keys(self) self.values = Values(self) self.items = Items(self) self._att_dict = { 'keys': self.setkeys, 'items': self.setitems, 'values': self.setvalues, }
Example #8
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def remove(self, item): raise TypeError('Can\'t remove items from values')
Example #9
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __imul__(self, n): raise TypeError('Can\'t multiply values in place')
Example #10
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __iadd__(self, other): raise TypeError('Can\'t add in place to values')
Example #11
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __delitem__(self, i): raise TypeError('Can\'t delete items from values')
Example #12
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __add__(self, other): return self._main.values() + other
Example #13
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def append(self, item): raise TypeError('Can\'t append items to values')
Example #14
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __repr__(self): return repr(self._main.values()) # FIXME: do we need to check if we are comparing with another ``Values`` # object? (like the __cast method of UserList)
Example #15
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __call__(self): """Pretend to be the values method.""" return self._main._values()
Example #16
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def rename(self, old_key, new_key): """ Rename the key for a given value, without modifying sequence order. 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 associated values, and the position of new_key in the sequence. >>> od = OrderedDict() >>> od['a'] = 1 >>> od['b'] = 2 >>> od.items() [('a', 1), ('b', 2)] >>> od.rename('b', 'c') >>> od.items() [('a', 1), ('c', 2)] >>> od.rename('c', 'a') Traceback (most recent call last): ValueError: New key already exists: 'a' >>> od.rename('d', 'b') Traceback (most recent call last): KeyError: 'd' """ if new_key == old_key: # no-op return if new_key in self: raise ValueError("New key already exists: %r" % new_key) # rename sequence entry value = self[old_key] old_idx = self._sequence.index(old_key) self._sequence[old_idx] = new_key # rename internal dict entry dict.__delitem__(self, old_key) dict.__setitem__(self, new_key, value)
Example #17
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def values(self, values=None): """ Return a list of all the values in the OrderedDict. 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. >>> d = OrderedDict(((1, 3), (3, 2), (2, 1))) >>> d.values() [3, 2, 1] """ return [self[key] for key in self._sequence]
Example #18
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __le__(self, other): return self._main.values() <= other
Example #19
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __setattr__(self, name, value): """Protect keys, items, and values.""" if not '_att_dict' in self.__dict__: object.__setattr__(self, name, value) else: try: fun = self._att_dict[name] except KeyError: OrderedDict.__setattr__(self, name, value) else: fun(value)
Example #20
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __init__(self, init_val=(), strict=True): OrderedDict.__init__(self, init_val, strict=strict) self._keys = self.keys self._values = self.values self._items = self.items self.keys = Keys(self) self.values = Values(self) self.items = Items(self) self._att_dict = { 'keys': self.setkeys, 'items': self.setitems, 'values': self.setvalues, }
Example #21
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def remove(self, item): raise TypeError('Can\'t remove items from values')
Example #22
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def pop(self, i=-1): raise TypeError('Can\'t pop items from values')
Example #23
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def insert(self, i, item): raise TypeError('Can\'t insert items into values')
Example #24
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def append(self, item): raise TypeError('Can\'t append items to values')
Example #25
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __imul__(self, n): raise TypeError('Can\'t multiply values in place')
Example #26
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __delitem__(self, i): raise TypeError('Can\'t delete items from values')
Example #27
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __radd__(self, other): return other + self._main.values() ## following methods not implemented for values ##
Example #28
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __add__(self, other): return self._main.values() + other
Example #29
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def __mul__(self, n): return self._main.values()*n
Example #30
Source File: odict.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def sort(self, *args, **kwds): """Sort the values.""" vals = self._main.values() vals.sort(*args, **kwds) self[:] = vals