首页 > 编程语言 > 详细

Python之路【第三篇】:Python基础(11)——set集合

时间:2016-05-28 06:36:26      阅读:203      评论:0      收藏:0      [点我收藏+]
old_dict = {
"#1":{ ‘hostname‘:‘c1‘, ‘cpu_count‘: 2, ‘mem_capicity‘: 80 },
"#2":{ ‘hostname‘:‘c1‘, ‘cpu_count‘: 2, ‘mem_capicity‘: 80 },
"#3":{ ‘hostname‘:‘c1‘, ‘cpu_count‘: 2, ‘mem_capicity‘: 80 }
}

# cmdb 新汇报的数据

new_dict = {
"#1":{ ‘hostname‘:‘c1‘, ‘cpu_count‘: 2, ‘mem_capicity‘: 800 },
"#3":{ ‘hostname‘:‘c1‘, ‘cpu_count‘: 2, ‘mem_capicity‘: 80 },
"#4":{ ‘hostname‘:‘c2‘, ‘cpu_count‘: 2, ‘mem_capicity‘: 80 }
}
#实现方式一,用for循环:
for k in new_dict:
# print(k)
old_dict[k] = new_dict[k]
# # print(new_dict[k])
# print(old_dict[k])
print(old_dict)
#实现方式二,直接用set集合的update方法:
old_dict.update(new_dict)
print(old_dict)

Python之路【第三篇】:Python基础(11)——set集合

原文:http://www.cnblogs.com/jiangnanmu/p/5536692.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!