本文实例讲述了Python实现合并字典的方法。分享给大家供大家参考。具体实现方法如下:
# 将两个字典合并
#!/usr/bin/python
def adddict(dict1,dict2):
xin = {}
for key in dict1.keys():
xin[key] = dict1[key]
for key in dict2.keys():
xin[key] = dict2[key]
return xin
s1 = {1:222,'c':'d','e':'f'}
s2 = {2:333,'g':'h','i':'j'}
print adddict(s1,s2)
希望本文所述对大家的Python程序设计有所帮助。
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8