Merging dictionaries in python
- Last modified: 10 February 2020
- Category: python tutorial
In this post we'll append multi dictionaries into mone by using a simple method, also we'll Iterate them. so let's do it.
#our dictionaries
dic_1 = {'name':'book', 'size':'55cm'}
dic_2 = {'name':'dog', 'size':'80cm'}
dic_3 = {'name':'canary', 'size':'10cm'}
#list to merge dictionaries
multi_dic = []
#append dic_1 to multi_dic
multi_dic.append(dic_1)
#append dic_2 to multi_dic
multi_dic.append(dic_3)
#append dic_3 to multi_dic
multi_dic.append(dic_3)
print(multi_dic)
output
[{'name': 'book', 'size': '55cm'}, {'name': 'canary', 'size': '10cm'}, {'name': 'canary', 'size': '10cm'}]
#loop multi_dic
for i in range(len(multi_dic)):
print(multi_dic[i]['name'])
output
book canary canary
English today is not an art to be mastered it's just a tool to use to get a result