{"id":21702,"date":"2021-10-28T08:46:05","date_gmt":"2021-10-28T03:16:05","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=21702"},"modified":"2023-01-23T17:31:50","modified_gmt":"2023-01-23T12:01:50","slug":"remove-key-from-dictionary-python-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/","title":{"rendered":"Remove key from dictionary Python | Example code"},"content":{"rendered":"\n<p>Using the <a href=\"https:\/\/tutorial.eyehunts.com\/python\/del-keyword-in-python-example-code\/\">del keyword<\/a> or <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-pop-function-first-by-value-pop-multiple-examples\/\">pop() function<\/a> can Remove the key from the dictionary Python.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>del my_dict&#91;'key']<\/code><\/pre>\n\n\n\n<p>OR<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_dict.pop('key', None)<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example Remove key from dictionary Python<\/strong><\/h2>\n\n\n\n<p>Simple example code.<\/p>\n\n\n\n<p><strong>Using del keyword<\/strong><\/p>\n\n\n\n<p>To delete a key regardless of whether it is in the dictionary, use the two-argument form of <a href=\"http:\/\/docs.python.org\/library\/stdtypes.html#dict.pop\"><code>dict.pop()<\/code><\/a>:<\/p>\n\n\n\n<p>This will return <code>my_dict[key]<\/code> if <code>key<\/code> exists in the dictionary, and <code>None<\/code> otherwise. If the second parameter is not specified (i.e. <code>my_dict.pop('key')<\/code>) and <code>key<\/code> does not exist, a <code>KeyError<\/code> is raised.<\/p>\n\n\n\n<p><em>Deleting the &#8216;D&#8217; key.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dic1 = {'A': 1, 'B': 5, 'C': 10, 'D': 15}\n\ndel dic1&#91;'D']\n\nprint(dic1)<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"330\" height=\"108\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg?resize=330%2C108&#038;ssl=1\" alt=\"Remove key from dictionary Python\" class=\"wp-image-21710\"\/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Using pop() function<\/strong><\/p>\n\n\n\n<p>To delete a key that is guaranteed to exist use it. This will raise a <code>KeyError<\/code> if the key is not in the dictionary.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dic1 = {'A': 1, 'B': 5, 'C': 10, 'D': 15}\n\ndic1.pop('D', None)\n\nprint(dic1)<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: {&#8216;A&#8217;: 1, &#8216;B&#8217;: 5, &#8216;C&#8217;: 10}<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How to remove multiple keys from the dictionary?<\/strong><\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use a for-loop to iterate through a list of keys to remove. At each iteration, use the syntax <code>del dict[key]<\/code> to remove <code>key<\/code> from <code>dict<\/code>.<\/p>\n\n\n\n<p>Same you can use <a href=\"https:\/\/kite.com\/python\/docs\/builtins.dict.pop\"><code>dict.pop(k)<\/code><\/a> to remove the current key <code>k<\/code> from <code>dict<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dic1 = {'A': 1, 'B': 5, 'C': 10, 'D': 15}\n\nremove = &#91;\"A\", \"B\"]\n\nfor key in remove:\n    del dic1&#91;key]\n\nprint(dic1)<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: {&#8216;C&#8217;: 10, &#8216;D&#8217;: 15}<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any doubts or suggestions on this Python dictionary code.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Using the del keyword or pop() function can Remove the key from the dictionary Python. OR Example Remove key from dictionary Python Simple example code. Using del keyword To delete a key regardless of whether it is in the dictionary, use the two-argument form of dict.pop(): This will return my_dict[key] if key exists in the&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Remove key from dictionary Python | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[136,101],"post_series":[],"class_list":["post-21702","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-code","tag-python-dictionary"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Remove key from dictionary Python | Example code<\/title>\n<meta name=\"description\" content=\"Using the del keyword or pop() function can Remove the key from dictionary Python. To delete a key that is guaranteed to exist use it. This..\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Remove key from dictionary Python | Example code\" \/>\n<meta property=\"og:description\" content=\"Using the del keyword or pop() function can Remove the key from dictionary Python. To delete a key that is guaranteed to exist use it. This..\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-28T03:16:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-23T12:01:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/\",\"name\":\"Remove key from dictionary Python | Example code\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg\",\"datePublished\":\"2021-10-28T03:16:05+00:00\",\"dateModified\":\"2023-01-23T12:01:50+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Using the del keyword or pop() function can Remove the key from dictionary Python. To delete a key that is guaranteed to exist use it. This..\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg?fit=330%2C108&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg?fit=330%2C108&ssl=1\",\"width\":330,\"height\":108},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Remove key from dictionary Python | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Remove key from dictionary Python | Example code","description":"Using the del keyword or pop() function can Remove the key from dictionary Python. To delete a key that is guaranteed to exist use it. This..","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:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/","og_locale":"en_US","og_type":"article","og_title":"Remove key from dictionary Python | Example code","og_description":"Using the del keyword or pop() function can Remove the key from dictionary Python. To delete a key that is guaranteed to exist use it. This..","og_url":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-10-28T03:16:05+00:00","article_modified_time":"2023-01-23T12:01:50+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/","name":"Remove key from dictionary Python | Example code","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg","datePublished":"2021-10-28T03:16:05+00:00","dateModified":"2023-01-23T12:01:50+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Using the del keyword or pop() function can Remove the key from dictionary Python. To delete a key that is guaranteed to exist use it. This..","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg?fit=330%2C108&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Remove-key-from-dictionary-Python.jpg?fit=330%2C108&ssl=1","width":330,"height":108},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/remove-key-from-dictionary-python-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Remove key from dictionary Python | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":18274,"url":"https:\/\/tutorial.eyehunts.com\/python\/del-dictionary-python-example-code\/","url_meta":{"origin":21702,"position":0},"title":"del dictionary Python | Example code","author":"Rohit","date":"November 11, 2021","format":false,"excerpt":"The del keyword is used to delete the whole dictionary or specific element from a dictionary in Python. Python del is actually a keyword that is basically used for the deletion of objects. Example del dictionary Python Simple example code deletes dictionary object. a_dict = {\"One\": 1, \"Two\": 2, \"Three\":\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"del dictionary Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-dictionary-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18304,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-duplicates-from-dictionary-example-code\/","url_meta":{"origin":21702,"position":1},"title":"Python remove duplicates from dictionary | Example code","author":"Rohit","date":"August 31, 2021","format":false,"excerpt":"We can use loop or dictionary comprehension to remove duplicates from the dictionary in Python. While removing a duplicate value from the dictionary the keys are also removed in the process. If you don't care about retaining the original order then set(my_list) will remove all duplicates. Example remove duplicates from\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python remove duplicates from dictionary","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-duplicates-from-dictionary.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":20590,"url":"https:\/\/tutorial.eyehunts.com\/python\/del-function-in-python-code\/","url_meta":{"origin":21702,"position":2},"title":"del function in Python | Code","author":"Rohit","date":"October 13, 2021","format":false,"excerpt":"Python has a del statement (keyword) to delete objects, not a del function. The del keyword is used to delete a list, or dictionaries, remove key-value pairs from a dictionary, delete variables, etc. del object_name Let's see del examples Delete Variables, the item from the list, and key-value from a\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/del-function-in-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":21692,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-replace-dictionary-key-example-code\/","url_meta":{"origin":21702,"position":3},"title":"Python replace dictionary key | Example code","author":"Rohit","date":"October 27, 2021","format":false,"excerpt":"Using the pop() or zip() function we can replace the dictionary key in Python. Even using the del keyword is possible. Examples of replacing dictionary key in Python A simple example changes the key of an entry in a Python dictionary. Using basic and del keyword Easily done in 2\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python replace dictionary key","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-replace-dictionary-key.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":33507,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-not-in-dictionary\/","url_meta":{"origin":21702,"position":4},"title":"Python not in dictionary","author":"Rohit","date":"July 19, 2023","format":false,"excerpt":"In Python, the not in keyword is used to check whether a key or value is present in a dictionary or any other iterable. It is typically used in combination with the in keyword to perform membership tests. For dictionaries, you can use not in to check if a specific\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/07\/Python-not-in-dictionary-1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":22512,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-dictionary-update-value-if-the-key-exists-example-code\/","url_meta":{"origin":21702,"position":5},"title":"Python dictionary update value if the key exists | Example code","author":"Rohit","date":"November 19, 2021","format":false,"excerpt":"Use the \"in\" keyword to check if keys exist. If exist then update the value of the dictionary in Python. If the key exists, we update its value by assigning a new value to the key using the assignment operator (=). Example dictionary update value if the key exists in\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python dictionary update value if key exists","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Python-dictionary-update-value-if-key-exists.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/21702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=21702"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/21702\/revisions"}],"predecessor-version":[{"id":35670,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/21702\/revisions\/35670"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=21702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=21702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=21702"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=21702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}