Python 字典值相加

#字典值相加
def union_dic(*objs):
    _keys = set(sum([obj.keys() for obj in objs],[]))
    _total = {}
    for _key in _keys:
        _total[_key] = sum([obj.get(_key,0) for obj in objs])
    return _total

 

posted @ 2014-10-31 10:24  王志超i  阅读(10989)  评论(0编辑  收藏  举报