utils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:charm-swift-proxy 作者: openstack 项目源码 文件源码
def ordered(orderme):
    """Converts the provided dictionary into a collections.OrderedDict.

    The items in the returned OrderedDict will be inserted based on the
    natural sort order of the keys. Nested dictionaries will also be sorted
    in order to ensure fully predictable ordering.

    :param orderme: the dict to order
    :return: collections.OrderedDict
    :raises: ValueError: if `orderme` isn't a dict instance.
    """
    if not isinstance(orderme, dict):
        raise ValueError('argument must be a dict type')

    result = OrderedDict()
    for k, v in sorted(six.iteritems(orderme), key=lambda x: x[0]):
        if isinstance(v, dict):
            result[k] = ordered(v)
        else:
            result[k] = v

    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号