{"id":975,"date":"2021-11-11T11:39:30","date_gmt":"2021-11-11T11:39:30","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=975"},"modified":"2024-02-18T10:05:18","modified_gmt":"2024-02-18T10:05:18","slug":"how-to-remove-duplicate-keys-from-dictionary-in-python","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/how-to-remove-duplicate-keys-from-dictionary-in-python\/","title":{"rendered":"How to remove duplicate keys from  dictionary in python"},"content":{"rendered":"\n<p>This python code will remove all duplicate keys and associate items from the dictionary. To remove we are using one temp array and using it for loop iterating each value. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>thisdict = {\n  &quot;1&quot;: &quot;C language&quot;,\n  &quot;2&quot;: &quot;Java Language&quot;,\n  &quot;4&quot;: &quot;Python Language&quot;,\n  &quot;3&quot;: &quot;C++&quot;,\n  &quot;4&quot;: &quot;Python Language&quot;,\n  &quot;3&quot;: &quot;C++&quot;,\n  &quot;5&quot;: &quot;C++&quot;,\n}\n#declare temp array\ntempA = []  \nuniqueDict = dict()\nfor key, val in thisdict.items():\n    if val not in tempA:\n        tempA.append(val)\n        uniqueDict[key] = val\n\nprint(uniqueDict)<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>{&#39;1&#39;: &#39;C language&#39;, &#39;2&#39;: &#39;Java Language&#39;, &#39;4&#39;: &#39;Python Language&#39;, &#39;3&#39;: &#39;C++&#39;}<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This python code will remove all duplicate keys and associate items from the dictionary. To remove we are using one temp array and using it for loop iterating each value.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[11],"tags":[],"class_list":["post-975","post","type-post","status-publish","format-standard","hentry","category-running-code-and-program"],"aioseo_notices":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"sparkling-featured":false,"sparkling-featured-fullwidth":false,"tab-small":false},"uagb_author_info":{"display_name":"program45_-rt8nb","author_link":"https:\/\/ethosspace.com\/programmers\/author\/program45_-rt8nb\/"},"uagb_comment_info":1,"uagb_excerpt":"This python code will remove all duplicate keys and associate items from the dictionary. To remove we are using one temp array and using it for loop iterating each value.","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/comments?post=975"}],"version-history":[{"count":1,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/975\/revisions"}],"predecessor-version":[{"id":976,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/975\/revisions\/976"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}