码迷,mamicode.com
首页 > 编程语言 > 详细

python合并多个字典组成一个字典

时间:2018-01-13 00:26:18      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:port   imp   rom   div   dict   import   log   weight   ict   

from collections import ChainMap
import collections
value = ChainMap()
for list_num in range(1,13):
li_list = list_num + 1
value["li_name%s"%(list_num)] = li_list
value=value.new_child()#添加字典到集合
value=value.parents#取出一个空字典
print(value)#打印合并后的字典
print(dict(value))#从对象中提取字典

+++++++++++++++++++++++++++++++++++++++++++++++
C:\python3.7\python.exe D:/Python-Test/StuProject/StuApp/tests.py
ChainMap({‘li_name1‘: 2, ‘li_name2‘: 3, ‘li_name3‘: 4, ‘li_name4‘: 5, ‘li_name5‘: 6, ‘li_name6‘: 7, ‘li_name7‘: 8, ‘li_name8‘: 9, ‘li_name9‘: 10, ‘li_name10‘: 11, ‘li_name11‘: 12, ‘li_name12‘: 13})
{‘li_name1‘: 2, ‘li_name4‘: 5, ‘li_name11‘: 12, ‘li_name2‘: 3, ‘li_name12‘: 13, ‘li_name7‘: 8, ‘li_name8‘: 9, ‘li_name5‘: 6, ‘li_name10‘: 11, ‘li_name3‘: 4, ‘li_name9‘: 10, ‘li_name6‘: 7}

python合并多个字典组成一个字典

标签:port   imp   rom   div   dict   import   log   weight   ict   

原文地址:https://www.cnblogs.com/acer-haitao/p/8277956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!