{"id":14077,"date":"2021-07-02T07:44:13","date_gmt":"2021-07-02T02:14:13","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=14077"},"modified":"2021-07-02T07:45:59","modified_gmt":"2021-07-02T02:15:59","slug":"python-increment-dictionary-value","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/","title":{"rendered":"Python Increment Dictionary Value: 5 Ways to Achieve"},"content":{"rendered":"\n<p>A dictionary in python is a built-in data structure that consists of a collection of items. The data is stored in the form of key-value<em> <\/em>pairs. Using the keys, we can access the value for that particular item. Each key is unique for a given dictionary. In python, we create dictionaries using curly braces ( <strong>&#8216;{ }&#8217; <\/strong>). Here each <em>key-value<\/em> pair is separated by a comma. By using dictionaries, each item stored inside it can be uniquely referenced by a key. In this article, we shall understand how in python, we can increment a dictionary value. <\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">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: #990303;color:#990303\" 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: #990303;color:#990303\" 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 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#How_to_increment_a_dictionary_value_in_python\" >How to increment a dictionary value 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:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#1_Using_if_statement\" >1. Using if statement<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#Let_us_understand_with_an_example\" >Let us understand with an example.<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#2_Using_get_function\" >2. Using get() function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#3_Implementing_the_setdefault_function\" >3. Implementing the setdefault() function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#4_By_defaultdict_function\" >4. By defaultdict() function<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#The_entire_code_is\" >The entire code is:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#5_Using_exception_handling\" >5. Using exception handling<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#Trending_Articles\" >Trending Articles<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-how-to-increment-a-dictionary-value-in-python\"><span class=\"ez-toc-section\" id=\"How_to_increment_a_dictionary_value_in_python\"><\/span>How to increment a dictionary value in python?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>As mentioned before, dictionary stores items in the form of key-value pairs. If we want to increment a dictionary value, we shall first have to check if the given key exists. Only if the key exists, then we will be able to increment its value. We can achieve that by using in-built functions, conditional statements, and exception handling. The ways to increment a dictionary value in python are:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Using if statement<\/strong><\/li><li><strong>Using get() function<\/strong><\/li><li><strong>Implementing the setdefault() function<\/strong><\/li><li><strong>By defaultdict() function<\/strong><\/li><li><strong>Using exception handling<\/strong><\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-1-using-if-statement\"><span class=\"ez-toc-section\" id=\"1_Using_if_statement\"><\/span>1. Using if statement <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can use an if statement to increment a dictionary value. Inside the if condition, we will check if the key exists or not. And if it does, only then will we increment its value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-let-us-understand-with-an-example\"><span class=\"ez-toc-section\" id=\"Let_us_understand_with_an_example\"><\/span>Let us understand with an example. <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>We shall consider a dictionary named<em> &#8216;quantity&#8217; <\/em>which consists of the quantities of instruments. The instrument names are the keys in the dictionary, and the instrument quantity is each key&#8217;s respective value. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n<\/pre><\/div>\n\n\n<p>Now, to increment the value of the key<em> &#8216;Flute&#8217;<\/em>, we shall save the key name in a variable<em> &#8216;key&#8217;.<\/em> Inside the if condition, we shall check if the key is present in the dictionary <em>&#8216;quantity&#8217;<\/em> or not. If the condition is true, we shall increment the key&#8217;s value by one. Else, we shall print a statement saying that the key does not exist.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nkey = 'Flute'\n\nif key in quantity:\n  print(&quot;Original dictionary:&quot;,quantity)\n  quantity&#x5B;key] += 1\n  print(&quot;Updated dictionary:&quot;,quantity)\nelse:\n  print('Key does not exist')\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Original dictionary: {'Piano': 30, 'Ukulele': 21, 'Flute': 10, 'Guitar': 18}\nUpdated dictionary: {'Piano': 30, 'Ukulele': 21, 'Flute': 11, 'Guitar': 18}<\/pre>\n\n\n\n<p>Here, the value of the key <em>&#8216;Flute&#8217; <\/em>has been incremented from 10 to 11. <\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>The entire code is:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nkey = 'Flute'\nif key in quantity:\n  print(&quot;Original dictionary:&quot;,quantity)\n  quantity&#x5B;key] += 1\n  print(&quot;Updated dictionary:&quot;,quantity)\nelse:\n  print('Key does not exist')\n<\/pre><\/div>\n\n\n<p>Let us take a key value which does not exist inside the dictionary. Then, in that case it should print that the key does not exist.<\/p>\n\n\n\n<p><strong>We have taken<em> key = &#8216;Violin&#8217; <\/em>as it does not exist in the dictionary<em> &#8216;quantity&#8217;. <\/em><\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nkey = 'Violin'\nif key in quantity:\n  print(&quot;Original dictionary:&quot;,quantity)\n  quantity&#x5B;key] += 1\n  print(&quot;Updated dictionary:&quot;,quantity)\nelse:\n  print('Key does not exist')\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Key does not exist<\/pre>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-alpha monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Trending<\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\">[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-using-get-function\"><span class=\"ez-toc-section\" id=\"2_Using_get_function\"><\/span><strong>2. Using get() function<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Implementing the<em> get()<\/em> function is another way of incrementing a dictionary value. The syntax of the <em>get()<\/em> function is:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndict.get(key, default=None)\n<\/pre><\/div>\n\n\n<p>It accepts the key value as an argument and checks if the key exists or not. If the key exists, then it returns the value of the key, and if it does not exist, it will return the default value. The default argument is <em>None <\/em>if not specified. <\/p>\n\n\n\n<p><strong>Let us take the same dictionary<em> &#8216;quantity&#8217; <\/em>from the above example.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n<\/pre><\/div>\n\n\n<p>Here, we want to increment the value with key<em> &#8216;Ukulele&#8217;.<\/em> We will store the key <em>&#8216;Ukulele&#8217; <\/em>inside a variable named<em> &#8216;key&#8217;.<\/em><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nkey = 'Ukulele'\n<\/pre><\/div>\n\n\n<p>Now, we shall use the<em> get()<\/em> function by<em> &#8216;quantity.get()&#8217;.<\/em> Inside <em>get()<\/em>, we shall pass the variable <em>&#8216;key&#8217;<\/em> as the first argument and the default value 0 as the second argument.<\/p>\n\n\n\n<p> We shall add 1 to the output of the get function for incrementing, which will be the value for the given key if it exists. If the key does not exist, then the function <em>get() <\/em>will return 0, and a new item with that key shall be created. The new item shall have a value of 1. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity&#x5B;key] = quantity.get(key,0) + 1\nprint(&quot;Dictionary:&quot;,quantity)\n<\/pre><\/div>\n\n\n<p>Since the key <em>&#8216;Ukulele&#8217; <\/em>exists in the dictionary<em> &#8216;quantity&#8217;<\/em>, its value gets incremented from 21 to 22. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nDictionary: {'Piano': 30, 'Ukulele': 22, 'Flute': 10, 'Guitar': 18}\n<\/pre><\/div>\n\n\n<p><strong>The entire code is:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nkey = 'Ukulele'\n\nquantity&#x5B;key] = quantity.get(key,0) + 1\nprint(&quot;Dictionary:&quot;,quantity)\n<\/pre><\/div>\n\n\n<p><strong>Had the key not existed, then that key would have been added to the dictionary.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nkey = 'Violin'\n\nquantity&#x5B;key] = quantity.get(key,0) + 1\nprint(&quot;Dictionary:&quot;,quantity)\n<\/pre><\/div>\n\n\n<p><strong>Since the key<em> &#8216;Violin&#8217; <\/em>does not exist, it got created as a new key with a value equal to 1.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nDictionary: {'Piano': 30, 'Ukulele': 21, 'Flute': 10, 'Guitar': 18, 'Violin': 1}\n<\/pre><\/div>\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background has-medium-font-size\"><strong>Also, Read | <\/strong><a href=\"http:\/\/www.pythonpool.com\/sort-dictionary-by-value-python\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span style=\"text-decoration: underline;\"><strong>How to Sort a Dictionary by Value in Python<\/strong><\/span><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-implementing-the-setdefault-function\"><span class=\"ez-toc-section\" id=\"3_Implementing_the_setdefault_function\"><\/span><strong>3. Implementing the setdefault() function<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can also use the built-in <em>setdefault() <\/em>function to increment a dictionary&#8217;s value. The working of the <em>setdefault() <\/em>function is similar to the <em>get() <\/em>function. It takes the key as an input and returns the value of that key if it exists in that dictionary. If it does not exist, then it will return the specified value. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>dictionary.setdefault(keyname, value)<\/em><\/pre>\n\n\n\n<p>We shall take the same example as above and use the <em>setdefault() <\/em>function instead of the <em>get()<\/em> function. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nkey = 'Ukulele'\n\nquantity&#x5B;key] = quantity.setdefault(key,0) + 1\nprint(&quot;Dictionary:&quot;,quantity)\n<\/pre><\/div>\n\n\n<p><strong>The value of <em>&#8216;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Ukulele\" target=\"_blank\" rel=\"noreferrer noopener\">Ukulele<\/a><\/em>&#8216; is incremented from 21 to 22.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nDictionary: {'Piano': 30, 'Ukulele': 22, 'Flute': 10, 'Guitar': 18}\n<\/pre><\/div>\n\n\n<p>Again if the key does not exist in the dictionary <em>&#8216;quantity&#8217;, <\/em>then it will create a new item with that key and value 1.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nkey = 'Violin'\n\nquantity&#x5B;key] = quantity.setdefault(key,0) + 1\nprint(&quot;Dictionary:&quot;,quantity)\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Dictionary: {'Piano': 30, 'Ukulele': 21, 'Flute': 10, 'Guitar': 18, 'Violin': 1}\n<\/pre>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-kilo monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Popular now<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><span class=\"monsterinsights-inline-popular-posts-border-2\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\">[Fixed] nameerror: name Unicode is not defined<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-4-by-defaultdict-function\"><span class=\"ez-toc-section\" id=\"4_By_defaultdict_function\"><\/span>4. By defaultdict() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If we try to use a dictionary key that does not exist, python will throw a <em>&#8216;KeyError&#8217;.<\/em> To prevent an error from being thrown while incrementing dictionary value, we can use the <em>defaultdict() <\/em>function. The <em>defaultdict()<\/em> function present in the collections library in python. Using defaultdict() will create a new item when the key is not present in the dictionary. <\/p>\n\n\n\n<p>Let us consider the same dictionary <em>&#8216;quantity&#8217; <\/em>as before. First, we shall import the <em>defaultdict<\/em> from the<em> collections <\/em>library. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom collections import defaultdict \n\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n<\/pre><\/div>\n\n\n<p>Now, we shall use the <em>defaultdict() <\/em>function. The first argument shall be the callable object, which in this case is an integer. The second argument is the dictionary<em> &#8216;quantity&#8217;. <\/em><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = defaultdict(int,quantity)\n<\/pre><\/div>\n\n\n<p>The key variable contains the value<em> &#8216;Flute&#8217; <\/em>. So, the value of <em>&#8216;key&#8217;<\/em> is incremented by one.  <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nkey = 'Flute'\n \nquantity&#x5B;key] += 1\n<\/pre><\/div>\n\n\n<p>Now we shall print the dictionary.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nprint(quantity) \n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">defaultdict(&lt;class 'int'>, {'Piano': 30, 'Ukulele': 21, 'Flute': 11, 'Guitar': 18})<\/pre>\n\n\n\n<p><strong>Here the value of<em> &#8216;Flute&#8217;<\/em> has been incremented by one.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-the-entire-code-is\"><span class=\"ez-toc-section\" id=\"The_entire_code_is\"><\/span><strong>The entire code is:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom collections import defaultdict \n\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nquantity = defaultdict(int,quantity)\n\nkey = 'Flute'\n \nquantity&#x5B;key] += 1\n \nprint(quantity)\n<\/pre><\/div>\n\n\n<p>Again here also if a key does not exist in the dictionary, then instead of throwing <em>KeyError<\/em>, it will create a new key &#8211; value pair.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom collections import defaultdict \n\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\n\nquantity = defaultdict(int,quantity)\n\nkey = 'Violin'\n \nquantity&#x5B;key] += 1\n \nprint(quantity) \n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">defaultdict(&lt;class 'int'>, {'Piano': 30, 'Ukulele': 21, 'Flute': 10, 'Guitar': 18, 'Violin': 1})\n<\/pre>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-india monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Trending:<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\" style=\"font-size:18px;\" href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\">[Solved] runtimeerror: cuda error: invalid device ordinal<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-5-using-exception-handling\"><span class=\"ez-toc-section\" id=\"5_Using_exception_handling\"><\/span>5. <strong>Using exception handling<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To prevent <em>KeyError<\/em> from being thrown while incrementing dictionary value, we can also perform exception handling.<\/p>\n\n\n\n<p>We will use a try &#8211; except block. Inside the try block we will try incrementing the value of the given key. If the key exists then its value will be incremented. But, if it does not exist, then it will throw a <em>KeyError <\/em>exception. <\/p>\n\n\n\n<p>The except block will catch the exception, and inside the except block, we will create a new item with that key. If we don&#8217;t want to create a new item, we can simply include a print statement saying that the key does not exist.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nkey = 'Piano'\n\ntry:\n  quantity&#x5B;key] += 1\nexcept KeyError:\n  quantity&#x5B;key] = 1\n\nprint(quantity)\n<\/pre><\/div>\n\n\n<p><strong>The output is:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{'Piano': 31, 'Ukulele': 21, 'Flute': 10, 'Guitar': 18}\n<\/pre>\n\n\n\n<p><strong>The value of the key &#8216;<em>Piano&#8217;<\/em> is incremented from 30 to 31. <\/strong><\/p>\n\n\n\n<p>If the key does not exist, then the except block will be executed.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nquantity = {'Piano' : 30, 'Ukulele' : 21, 'Flute' : 10, 'Guitar' : 18}\n\nkey = 'Drum'\n\ntry:\n  quantity&#x5B;key] += 1\nexcept KeyError:\n  quantity&#x5B;key] = 1\n\nprint(quantity) \n\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{'Piano': 30, 'Ukulele': 21, 'Flute': 10, 'Guitar': 18, 'Drum': 1}\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\"\/>\n\n\n\n<p>That sums up everything about<em> Incrementing Dictionary Value in Python<\/em>. If you have any questions in your mind, feel free to leave them in the comments below.<\/p>\n\n\n\n<p><em>Until next time, Keep Learning!<\/em><\/p>\n\n\n<div class=\"monsterinsights-widget-popular-posts monsterinsights-widget-popular-posts-beta monsterinsights-popular-posts-styled monsterinsights-widget-popular-posts-columns-1\"><h2 class=\"monsterinsights-widget-popular-posts-widget-title\"><span class=\"ez-toc-section\" id=\"Trending_Articles\"><\/span>Trending Articles<span class=\"ez-toc-section-end\"><\/span><\/h2><ul class=\"monsterinsights-widget-popular-posts-list\"><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" style=\"color:#000000;font-size:18px;\">[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" style=\"color:#000000;font-size:18px;\">[Fixed] nameerror: name Unicode is not defined<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" style=\"color:#000000;font-size:18px;\">[Solved] runtimeerror: cuda error: invalid device ordinal<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-type-numpy-ndarray-doesnt-define-__round__-method\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" style=\"color:#000000;font-size:18px;\">[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><\/ul><\/div><p><\/p>","protected":false},"excerpt":{"rendered":"<p>A dictionary in python is a built-in data structure that consists of a collection of items. The data is stored in the form of key-value &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Python Increment Dictionary Value: 5 Ways to Achieve\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#more-14077\" aria-label=\"More on Python Increment Dictionary Value: 5 Ways to Achieve\">Read more<\/a><\/p>\n","protected":false},"author":20,"featured_media":14135,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[4287,4291,4289,4292,4290,4288],"class_list":["post-14077","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-how-to-increment-value-in-dictionary-python","tag-increment-dictionary-value-python","tag-increment-value-in-dictionary-python","tag-python-dictionary-how-to-increment-value","tag-python-dictionary-increment-value","tag-python-increment-value-in-dictionary","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Increment Dictionary Value: 5 Ways to Achieve - Python Pool<\/title>\n<meta name=\"description\" content=\"To increment dictionary value in python, we can use several in-built functions, conditional statement and exception handling.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Increment Dictionary Value: 5 Ways to Achieve\" \/>\n<meta property=\"og:description\" content=\"A dictionary in python is a built-in data structure that consists of a collection of items. The data is stored in the form of key-value pairs. Using the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-02T02:14:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-02T02:15:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dhruvi Vikma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dhruvi Vikma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/\"},\"author\":{\"name\":\"Dhruvi Vikma\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23\"},\"headline\":\"Python Increment Dictionary Value: 5 Ways to Achieve\",\"datePublished\":\"2021-07-02T02:14:13+00:00\",\"dateModified\":\"2021-07-02T02:15:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/\"},\"wordCount\":1104,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg\",\"keywords\":[\"how to increment value in dictionary python\",\"increment dictionary value python\",\"increment value in dictionary python\",\"python dictionary how to increment value\",\"python dictionary increment value\",\"python increment value in dictionary\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/\",\"name\":\"Python Increment Dictionary Value: 5 Ways to Achieve - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg\",\"datePublished\":\"2021-07-02T02:14:13+00:00\",\"dateModified\":\"2021-07-02T02:15:59+00:00\",\"description\":\"To increment dictionary value in python, we can use several in-built functions, conditional statement and exception handling.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg\",\"width\":1200,\"height\":628,\"caption\":\"Python increment Dictionary Value\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Increment Dictionary Value: 5 Ways to Achieve\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23\",\"name\":\"Dhruvi Vikma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g\",\"caption\":\"Dhruvi Vikma\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Increment Dictionary Value: 5 Ways to Achieve - Python Pool","description":"To increment dictionary value in python, we can use several in-built functions, conditional statement and exception handling.","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:\/\/www.pythonpool.com\/python-increment-dictionary-value\/","og_locale":"en_US","og_type":"article","og_title":"Python Increment Dictionary Value: 5 Ways to Achieve","og_description":"A dictionary in python is a built-in data structure that consists of a collection of items. The data is stored in the form of key-value pairs. Using the","og_url":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/","og_site_name":"Python Pool","article_published_time":"2021-07-02T02:14:13+00:00","article_modified_time":"2021-07-02T02:15:59+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg","type":"image\/jpeg"}],"author":"Dhruvi Vikma","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Dhruvi Vikma","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/"},"author":{"name":"Dhruvi Vikma","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23"},"headline":"Python Increment Dictionary Value: 5 Ways to Achieve","datePublished":"2021-07-02T02:14:13+00:00","dateModified":"2021-07-02T02:15:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/"},"wordCount":1104,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg","keywords":["how to increment value in dictionary python","increment dictionary value python","increment value in dictionary python","python dictionary how to increment value","python dictionary increment value","python increment value in dictionary"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/","url":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/","name":"Python Increment Dictionary Value: 5 Ways to Achieve - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg","datePublished":"2021-07-02T02:14:13+00:00","dateModified":"2021-07-02T02:15:59+00:00","description":"To increment dictionary value in python, we can use several in-built functions, conditional statement and exception handling.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/Python-increment-Dictionary-Value.jpg","width":1200,"height":628,"caption":"Python increment Dictionary Value"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-increment-dictionary-value\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Python Increment Dictionary Value: 5 Ways to Achieve"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/bed8fc40c7b71baf7d76b1cfefd79f23","name":"Dhruvi Vikma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/520d8a37e8b6ce4e6df57e997dc0d571225f48098bbb02838c3884bb603e886f?s=96&d=wavatar&r=g","caption":"Dhruvi Vikma"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/14077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=14077"}],"version-history":[{"count":28,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/14077\/revisions"}],"predecessor-version":[{"id":14149,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/14077\/revisions\/14149"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/14135"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=14077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=14077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=14077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}