{"id":5114,"date":"2024-10-15T09:33:41","date_gmt":"2024-10-15T09:33:41","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=5114"},"modified":"2025-05-20T04:32:48","modified_gmt":"2025-05-20T04:32:48","slug":"how-to-merge-two-dictionaries-in-python","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/","title":{"rendered":"How to Merge Two Dictionaries in Python"},"content":{"rendered":"\n<p>Python dictionary is a popular data structure that allows you to easily store a large amount of different data in a compact manner, as key-value pairs. They are commonly used by web developers since they can be directly converted to JSON and vice versa. Often, Python developers need to merge dictionaries in Python as part of software development. There are several ways to combine Python dictionaries. In this article, we will learn how to merge two dictionaries in Python.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#How_to_Merge_Two_Dictionaries_in_Python\" >How to Merge Two Dictionaries in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#1_Using_update\" >1. Using update()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#2_Using_Unpacking_operator\" >2. Using Unpacking operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#3_Using_%E2%80%9C%E2%80%9D_operator\" >3. Using &#8220;|&#8221; operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#4_Using_Loop_Keys\" >4. Using Loop &amp; Keys<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#5_Using_operator\" >5. Using |= operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Merge_Two_Dictionaries_in_Python\"><\/span>How to Merge Two Dictionaries in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to merge two dictionaries in Python. Before we proceed, it is important to understand that some of these solutions produce a new dictionary while others overwrite one of the two dictionaries. Also, if the dictionaries contain common keys, then the order of merge will decide the final values of duplicate keys. It is important to consider these factors before you choose a way to merge dictionaries.<\/p>\n\n\n\n<p>Let us say we have the following 3 dictionaries &#8211; d1 and d2 that do not have any common keys whereas d1 and d3 have a common key &#8216;b&#8217;. Let us look at the different ways to merge two Python dictionaries.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1 = {'a':1, 'b' : 2}<br>d2 = {'c':3, 'd' : 4}<br>d3 = {'b':5, 'e' : 6}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_update\"><\/span>1. Using update()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can use update() function to easily merge one dictionary into another. In this case, it will not result in a new dictionary but one of the dictionaries will be overwritten with the merged dictionary. Here is an example to merge d1 and d2.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1 = {'a':1, 'b' : 2}<br>d2 = {'c':3, 'd' : 4}<br>d3 = {'b':5, 'e' : 6}<br><br>d1.update(d2)<br>print(d1) # output is {'a': 1, 'b': 2, 'c': 3, 'd': 4}<\/pre>\n\n\n\n<p>As you can see, the dictionary d1 has been updated. On the other hand, if you reverse d1 and d2 in above command, you will see that d2 has been updated.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d2.update(d1)\nprint(d2) # output is {'c': 3, 'd': 4, 'a': 1, 'b': 2}<\/pre>\n\n\n\n<p>In both the above cases, the merged dictionary is the same but different dictionary is overwritten. So the order of merge is important while using update() function.<\/p>\n\n\n\n<p>In both the above examples, d1 and d2 do not have any common keys. Let us see what happens if there is a duplicate key in the two dictionaries, such as in case of d1 and d3.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1.update(d3)<br>print(d1)  # output is {'a': 1, 'b': 5, 'e': 6}<\/pre>\n\n\n\n<p>As you can see, the dictionary d1 has been updated. Also, the value of duplicate key &#8216;b&#8217; is equal to its value in the 2nd dictionary d3. On the other hand, if you reverse d1 and d3 in above command, you will see that d3 has been updated.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d3.update(d1)<br>print(d3) # output is {'b': 2, 'e': 6, 'a': 1}<\/pre>\n\n\n\n<p>As you can see, the order of merge determines which dictionary is updated. In this case, the value of duplicate key &#8216;b&#8217; is equal to its value in the 2nd dictionary d1.<\/p>\n\n\n\n<p>Please note, once the dictionary is merged and updated, you will not be able to get back your original dictionary. <\/p>\n\n\n\n<p>If you want to retain original dictionaries and save the merge dictionary separately, then you need to create a copy of one of the dictionaries and then use it with update() function as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d4 =d1.copy()<br>d4.update(d2)<br>print(d4)  # output is {'a': 1, 'b': 2, 'c': 3, 'd': 4}<br>print(d1)  # output is {'a': 1, 'b': 2}<\/pre>\n\n\n\n<p>update() method can also be used to <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-data-from-one-dictionary-to-another-in-python\/\">copy data from one dictionary to another<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_Unpacking_operator\"><\/span>2. Using Unpacking operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The unpacking operator &#8216;**&#8217;, also known as double star operator, is another easy way to quickly merge two or more dictionaries at one go. However, unlike update() function, this method results in a new dictionary and does not update any of the existing ones. Here is an example to merge dictionaries d1 and d2.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1 = {'a':1, 'b' : 2}<br>d2 = {'c':3, 'd' : 4}<br>d3 = {'b':5, 'e' : 6}<br><br>d4 = {**d1, **d2}<br>print(d4) # output is {'a': 1, 'b': 2, 'c': 3, 'd': 4<br>print(d1) # output is {'a': 1, 'b': 2}<br>print(d2) # output is {'c': 3, 'd': 4}<\/pre>\n\n\n\n<p>In the above case, the dictionary d1&#8217;s items are first written to d4 and then dictionary d2&#8217;s items are written to it. If there are any duplicate keys, then the values of 1st dictionary are overwritten by those of the 2nd dictionary.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d4 = {**d1, **d3}<br>print(d4) # output is {'a': 1, 'b': 5, 'e': 6}<br><br>d4 = {**d3, **d1}<br>print(d4) # output is {'b': 2, 'e': 6, 'a': 1}<\/pre>\n\n\n\n<p>In the above 2 examples, d1 and d3 have a common key &#8216;b&#8217;. In first case, the the value of &#8216;b&#8217; is equal to that in d3 whereas in the 2nd case it is equal to that in d1. So the order of merging is important in this case. In both the above cases, the duplicate keys present in first dictionary are replaced by those in second dictionary.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_%E2%80%9C%E2%80%9D_operator\"><\/span>3. Using &#8220;|&#8221; operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Starting Python 3.9, you can also use &#8216;I&#8217; union operator to easily merge Python dictionaries. Its syntax is similar to concatenating string variables. It results in a new separate dictionary. Here is an example to merge dictionaries d1 and d2.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1 = {'a':1, 'b' : 2}<br>d2 = {'c':3, 'd' : 4}<br>d3 = {'b':5, 'e' : 6}<br><br>d4 = d1 | d2<br>print(d4) # output is {'a': 1, 'b': 2, 'c': 3, 'd': 4}<\/pre>\n\n\n\n<p>If there are no duplicate keys, as shown above, then the order of dictionaries does not matter. Otherwise, it matters. Here is an example to merge dictionaries d1 and d3 which have duplicate key &#8216;b&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d4 = d1 | d3<br>print(d4)  # {'a': 1, 'b': 5, 'e': 6}<br>d4 = d3 | d1<br>print(d4)  # {'b': 2, 'e': 6, 'a': 1}<\/pre>\n\n\n\n<p>In both the examples, the duplicate key of first dictionary is overwritten by that of the second dictionary. That is why you will see the result is different in both the cases. Therefore, the order of dictionary is important if you have duplicate keys.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_Loop_Keys\"><\/span>4. Using Loop &amp; Keys<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is the old fashioned way of looping through one dictionary and adding its key-value pairs to the other one. Here is an example to merge dictionaries d1 and d2 this way. We use keys() function to get a list of dictionary keys. Then we loop through them, and add those key-value pairs to the other dictionary.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1 = {'a':1, 'b' : 2}<br>d2 = {'c':3, 'd' : 4}<br>d3 = {'b':5, 'e' : 6}<br><br>for i in d2.keys():<br>        d1[i]=d2[i]<br>print(d1)  # output is {'a': 1, 'b': 2, 'c': 3, 'd': 4}<\/pre>\n\n\n\n<p>In this case, you do not get a new dictionary but the items of d2 are added to d1. If you switch d1 and d2 in above code, then d2 is updated and d1 remains unchanged.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in d1.keys():<br>        d2[i]=d1[i]<br>print(d2)  # output is {'c': 3, 'd': 4, 'a': 1, 'b': 2}<\/pre>\n\n\n\n<p>So as you can see, the order of dictionaries is important since it decides which dictionary should be updated.<\/p>\n\n\n\n<p>Since the two dictionaries do not have any common items, the merged dictionary contains the same key-value pairs. But if there are duplicate keys, then the keys of first dictionary are overwritten by those of the second dictionary.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in d3.keys():<br>        d1[i]=d3[i]<br>print(d1) # output is {'a': 1, 'b': 5, 'e': 6}<br><br>for i in d1.keys():<br>        d3[i]=d1[i]<br>print(d3) # output is {'b': 2, 'e': 6, 'a': 1}<\/pre>\n\n\n\n<p>Although this method is longer compared to others, it gives you more control to selectively merge items, which is not available with any of the other methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_operator\"><\/span>5. Using |= operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The |= operator also allows you to merge two dictionaries in Python quickly. It is also known as update operator and works like update() function seen above. It is slightly different from &#8216;|&#8217; operator seen earlier, which returns a new dictionary. The |= updates one of the two dictionaries instead of creating a new one altogether. Here is an example to merge dictionaries d1 and d2.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1 = {'a':1, 'b' : 2}<br>d2 = {'c':3, 'd' : 4}<br>d3 = {'b':5, 'e' : 6}<br><br>d1 |= d2<br>print(d1)  # output is {'a': 1, 'b': 2, 'c': 3, 'd': 4}<\/pre>\n\n\n\n<p>On the other hand, if we switch d1 and d2 in above expression, it will update d2 instead of d1.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d2 |= d1<br>print(d2)  # output is {'c': 3, 'd': 4, 'a': 1, 'b': 2}<\/pre>\n\n\n\n<p>If there are duplicate keys in the 2 dictionaries, then the keys of first dictionary are updated by those of the second dictionary. Here also order of dictionaries is important.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d3 |= d1<br>print(d3) # output is {'b': 2, 'e': 6, 'a': 1}<br><br>d1 |= d3<br>print(d1) # output is {'a': 1, 'b': 5, 'e': 6}<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt how to merge two dictionaries in Python. It is important to consider the order of specifying dictionaries, if the solution does not create a new dictionary but overwrites one of the two dictionaries. It is also important, in case the two dictionaries have duplicate keys. If the two dictionaries do not have any duplicate keys and your method gives a new dictionary then the order of dictionaries does not matter. Keeping these factors in mind, go through the above solutions one by one and pick the method that fits your requirement.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/\">How to Split List Into Even Chunks in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-backup-mysql-database-in-python\/\">How to Backup MySQL Database in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/what-does-if-__name__-__main__-do\/\">What Does Name-Main Idiom Do in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/\">What Are Metaclasses in Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to merge two dictionaries in Python. Here are different ways to merge Python dictionaries.<\/p>\n","protected":false},"author":1,"featured_media":5135,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[321],"class_list":["post-5114","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-merge-dictionaries"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Merge Two Dictionaries in Python - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to merge two dictionaries in Python. Here are different ways to merge Python dictionaries.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Merge Two Dictionaries in Python - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to merge two dictionaries in Python. Here are different ways to merge Python dictionaries.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-15T09:33:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-20T04:32:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"308\" \/>\n\t<meta property=\"og:image:height\" content=\"204\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Merge Two Dictionaries in Python\",\"datePublished\":\"2024-10-15T09:33:41+00:00\",\"dateModified\":\"2025-05-20T04:32:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/\"},\"wordCount\":1208,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1\",\"keywords\":[\"merge dictionaries\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/\",\"name\":\"How to Merge Two Dictionaries in Python - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1\",\"datePublished\":\"2024-10-15T09:33:41+00:00\",\"dateModified\":\"2025-05-20T04:32:48+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to merge two dictionaries in Python. Here are different ways to merge Python dictionaries.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1\",\"width\":308,\"height\":204,\"caption\":\"merge dictionaries in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Merge Two Dictionaries in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/\"],\"url\":\"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Merge Two Dictionaries in Python - Ubiq BI","description":"Sometimes you may need to merge two dictionaries in Python. Here are different ways to merge Python dictionaries.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Merge Two Dictionaries in Python - Ubiq BI","og_description":"Sometimes you may need to merge two dictionaries in Python. Here are different ways to merge Python dictionaries.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2024-10-15T09:33:41+00:00","article_modified_time":"2025-05-20T04:32:48+00:00","og_image":[{"width":308,"height":204,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Merge Two Dictionaries in Python","datePublished":"2024-10-15T09:33:41+00:00","dateModified":"2025-05-20T04:32:48+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/"},"wordCount":1208,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1","keywords":["merge dictionaries"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/","name":"How to Merge Two Dictionaries in Python - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1","datePublished":"2024-10-15T09:33:41+00:00","dateModified":"2025-05-20T04:32:48+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to merge two dictionaries in Python. Here are different ways to merge Python dictionaries.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1","width":308,"height":204,"caption":"merge dictionaries in python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Merge Two Dictionaries in Python"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/merge-dictionaries-in-python.jpg?fit=308%2C204&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1ku","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=5114"}],"version-history":[{"count":27,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5114\/revisions"}],"predecessor-version":[{"id":8301,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5114\/revisions\/8301"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/5135"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=5114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=5114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=5114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}