当前位置: 首页>>代码示例>>Python>>正文


Python OrderedDict.values方法代码示例

本文整理汇总了Python中collections.OrderedDict.values方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.values方法的具体用法?Python OrderedDict.values怎么用?Python OrderedDict.values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collections.OrderedDict的用法示例。


在下文中一共展示了OrderedDict.values方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setvalues

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
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 ### 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:24,代码来源:odict.py

示例2: __setitem__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
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 ### 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:24,代码来源:odict.py

示例3: items

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
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()) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:15,代码来源:odict.py

示例4: values

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
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] 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:14,代码来源:odict.py

示例5: rename

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
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) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:37,代码来源:odict.py

示例6: __call__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def __call__(self):
        """Pretend to be the values method."""
        return self._main._values() 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:5,代码来源:odict.py

示例7: __repr__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
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) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:6,代码来源:odict.py

示例8: __lt__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def __lt__(self, other): return self._main.values() <  other 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:3,代码来源:odict.py

示例9: __le__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def __le__(self, other): return self._main.values() <= other 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:3,代码来源:odict.py

示例10: __eq__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def __eq__(self, other): return self._main.values() == other 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:3,代码来源:odict.py

示例11: __ne__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def __ne__(self, other): return self._main.values() != other 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:3,代码来源:odict.py

示例12: __ge__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def __ge__(self, other): return self._main.values() >= other 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:3,代码来源:odict.py

示例13: __cmp__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def __cmp__(self, other): return cmp(self._main.values(), other) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:3,代码来源:odict.py

示例14: __contains__

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def __contains__(self, item): return item in self._main.values() 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:3,代码来源:odict.py

示例15: count

# 需要导入模块: from collections import OrderedDict [as 别名]
# 或者: from collections.OrderedDict import values [as 别名]
def count(self, item): return self._main.values().count(item) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:3,代码来源:odict.py


注:本文中的collections.OrderedDict.values方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。