{"id":75892,"date":"2020-01-31T14:01:23","date_gmt":"2020-01-31T08:31:23","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=75892"},"modified":"2020-01-31T14:01:23","modified_gmt":"2020-01-31T08:31:23","slug":"python-counter","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/python-counter\/","title":{"rendered":"Python Counter &#8211; Learn to create, access, and assign counters in Python"},"content":{"rendered":"<p>In this article, we will talk about <strong>Counter<\/strong> in Python. This is a class in the <strong>collections module<\/strong>.<\/p>\n<p>Other classes are <strong>defaultdict<\/strong>, <strong>OrderedDict<\/strong> and <strong>namedtuple<\/strong>. Let&#8217;s first discuss the concept of Python counter.<\/p>\n<h3>What is a Counter in Python?<\/h3>\n<p>A <strong>counter<\/strong> is a <strong>container<\/strong> in the <strong>collections module<\/strong>. It is a <strong>subclass<\/strong> of <strong>dict<\/strong> and it is an <strong>unordered collection<\/strong> in which <strong>elements<\/strong> and their <strong>counts<\/strong> are <strong>stored<\/strong> as a <strong>dictionary<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; from collections import Counter\n&gt;&gt;&gt; issubclass(Counter,dict)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h3>Creating a Python Counter<\/h3>\n<p>We can <strong>create<\/strong> a <strong>counter<\/strong> with a <strong>parameter<\/strong> that can be:<\/p>\n<ul>\n<li>A <strong>sequence<\/strong> of items &#8211; like a <strong>list<\/strong> or <strong>tuple<\/strong> or <strong>string<\/strong>.<\/li>\n<li><strong>Dictionary<\/strong> with <strong>keys<\/strong> and <strong>counts<\/strong>.<\/li>\n<li><strong>Keyword arguments<\/strong> with <strong>string<\/strong> <strong>names<\/strong> and <strong>counts<\/strong>.<\/li>\n<\/ul>\n<p>Let\u2019s take an example.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; Counter([1, 2, 1, 3, 4, 2, 1, 1])<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({1: 4, 2: 2, 3: 1, 4: 1})<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; Counter({1:4, 2:2, 3:1, 4:1})<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({1: 4, 2: 2, 3: 1, 4: 1})<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; Counter(A=3, B=2, C=1, D=4)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;D&#8217;: 4, &#8216;A&#8217;: 3, &#8216;B&#8217;: 2, &#8216;C&#8217;: 1})<\/div>\n<h3>Updating a Counter in Python<\/h3>\n<p>If you don\u2019t know the <strong>elements<\/strong> to <strong>add<\/strong> in a <strong>counter<\/strong>, you can <strong>create<\/strong> an <strong>empty counter<\/strong> and <strong>add<\/strong> them <strong>later<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums=Counter()\n&gt;&gt;&gt; nums.update([1,2,1,3,4,2,1,1])\n&gt;&gt;&gt; nums<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({1: 4, 2: 2, 3: 1, 4: 1})<\/div>\n<p>The <strong>update()<\/strong> method lets us <strong>add sequences<\/strong> or <strong>dictionaries<\/strong> or <strong>keyword arguments<\/strong> later.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums.update({1:2,2:2})\n&gt;&gt;&gt; nums<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({1: 6, 2: 4, 3: 1, 4: 1})<\/div>\n<p>It does not replace the <strong>counts<\/strong> in the counter, it <strong>adds<\/strong> to <strong>them<\/strong>.<\/p>\n<h3>Accessing Elements in Python Counter<\/h3>\n<p>To get the <strong>list<\/strong> of <strong>elements<\/strong> in the <strong>counter<\/strong> we can use the <strong>elements()<\/strong> method. It returns an <strong>iterator<\/strong> object for the <strong>values<\/strong> in the Counter.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c=Counter(A=3, B=2, C=1, D=4)\n&gt;&gt;&gt; c.elements()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&lt;itertools.chain object at 0x00000210EF4C4248&gt;<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; for elem in c.elements():\n  print(elem)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">A<br \/>\nA<br \/>\nA<br \/>\nB<br \/>\nB<br \/>\nC<br \/>\nD<br \/>\nD<br \/>\nD<br \/>\nD<\/div>\n<p>To <strong>delete<\/strong> an <strong>element<\/strong>, you can use the <strong>del keyword<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; del c['B']\n&gt;&gt;&gt; c<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;D&#8217;: 4, &#8216;A&#8217;: 3, &#8216;C&#8217;: 1})<\/div>\n<h3>Accessing Counts in Python Counter<\/h3>\n<p>We can use <strong>indexing<\/strong> to access the <strong>counts<\/strong> in a <strong>Python counter<\/strong>. Whatever <strong>element<\/strong> we want to get the <strong>count<\/strong> of, we will use it as the <strong>index<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums[2]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">4<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c=Counter(A=3, B=2, C=1, D=4)\n&gt;&gt;&gt; c['B']<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c['E']<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">0<\/div>\n<p><strong>E<\/strong> is <strong>not<\/strong> in the <strong>counter object<\/strong>, so it <strong>returns 0. <\/strong>This raises a <strong>KeyError<\/strong> for <strong>dictionaries<\/strong>. We can also get the <strong>counts<\/strong> of <strong>all items<\/strong> in a <strong>sequence<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; for val in 'ABCD':\n  print(val, c[val])<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">A 3<br \/>\nB 2<br \/>\nC 1<br \/>\nD 4<\/div>\n<h3>Reassigning Counts in Python Counter<\/h3>\n<p>The <strong>update()<\/strong> method <strong>adds<\/strong> to the <strong>counts<\/strong> in the <strong>Python counter<\/strong> but <strong>does not<\/strong> <strong>replace<\/strong> them. If you want to <strong>replace<\/strong> them, you can use the <strong>assignment operator<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c=Counter(A=3, B=2, C=1, D=4)\n&gt;&gt;&gt; c['B']=4\n&gt;&gt;&gt; c<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;B&#8217;: 4, &#8216;D&#8217;: 4, &#8216;A&#8217;: 3, &#8216;C&#8217;: 1})<\/div>\n<p>You can also clear the <strong>counts<\/strong> with the <strong>clear()<\/strong> method.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c.clear()\n&gt;&gt;&gt; c<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter()<\/div>\n<h3>Getting Most Common Values in Python Counter<\/h3>\n<p>The <strong>most_common()<\/strong> method gives us the <strong>most common<\/strong> values in the <strong>Python counter<\/strong>. These are the <strong>values<\/strong> with the <strong>highest counts<\/strong> in the <strong>counter<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c=Counter(A=3, B=2, C=1, D=4, E=2, F=4)\n&gt;&gt;&gt; c.most_common()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[(&#8216;D&#8217;, 4), (&#8216;F&#8217;, 4), (&#8216;A&#8217;, 3), (&#8216;B&#8217;, 2), (&#8216;E&#8217;, 2), (&#8216;C&#8217;, 1)]<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c.most_common(1)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[(&#8216;D&#8217;, 4)]<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c.most_common(2)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[(&#8216;D&#8217;, 4), (&#8216;F&#8217;, 4)]<\/div>\n<p><strong>D<\/strong> and <strong>F<\/strong> are the most <strong>common values<\/strong> in this <strong>counter<\/strong>.<\/p>\n<p>If we <strong>do not<\/strong> <strong>provide<\/strong> a <strong>parameter value<\/strong>, it <strong>prints<\/strong> all <strong>values<\/strong> and their <strong>counts<\/strong>.<\/p>\n<h3>Python Counter Arithmetic<\/h3>\n<p>Like we <strong>add<\/strong> the <strong>integers 2<\/strong> and <strong>3<\/strong>, we can perform <strong>counter arithmetic<\/strong> on <strong>counters<\/strong>.<\/p>\n<p>Let\u2019s take <strong>two counters<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c1=Counter(A=3, B=2, C=1, D=4, E=2)\n&gt;&gt;&gt; c2=Counter(A=2, B=3, C=1, D=5, E=1, F=4)<\/pre>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c1+c2<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;D&#8217;: 9, &#8216;A&#8217;: 5, &#8216;B&#8217;: 5, &#8216;F&#8217;: 4, &#8216;E&#8217;: 3, &#8216;C&#8217;: 2})<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c1-c2<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;A&#8217;: 1, &#8216;E&#8217;: 1})<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c2-c1<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;F&#8217;: 4, &#8216;B&#8217;: 1, &#8216;D&#8217;: 1})<\/div>\n<p><strong>Counters<\/strong> can have <strong>negative counts<\/strong> too.<\/p>\n<p>The<strong> subtract()<\/strong> method gives us <strong>negative counts<\/strong> too but the &#8211; <strong>operator doesn\u2019t<\/strong>. Now we can<strong> add c2<\/strong> back to <strong>c1<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c1.__add__(c2)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;D&#8217;: 4, &#8216;A&#8217;: 3, &#8216;B&#8217;: 2, &#8216;E&#8217;: 2, &#8216;C&#8217;: 1})<\/div>\n<p>We can<strong> \u2018and\u2019<\/strong> and <strong>\u2018or\u2019<\/strong> counters.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c1&amp;c2<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;A&#8217;: 1, &#8216;E&#8217;: 1})<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c1|c2<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;D&#8217;: 5, &#8216;F&#8217;: 4, &#8216;B&#8217;: 3, &#8216;A&#8217;: 2, &#8216;C&#8217;: 1, &#8216;E&#8217;: 1})<\/div>\n<p>But we<strong> cannot XOR<\/strong> them.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c1^c2<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Traceback (most recent call last):<br \/>\n<span style=\"font-weight: 400\">\u00a0\u00a0<\/span>File &#8220;&lt;pyshell#50&gt;&#8221;, line 1, in &lt;module&gt;<br \/>\n<span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0<\/span>c1^c2<br \/>\nTypeError: unsupported operand type(s) for ^: &#8216;Counter&#8217; and &#8216;Counter&#8217;<\/div>\n<p>We can also use the <strong>unary<\/strong> &#8211; <strong>operator<\/strong> with a <strong>counter<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; c1<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;A&#8217;: 1, &#8216;E&#8217;: 1, &#8216;C&#8217;: 0, &#8216;B&#8217;: -1, &#8216;D&#8217;: -1, &#8216;F&#8217;: -4})<\/div>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; -c1<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Counter({&#8216;F&#8217;: 4, &#8216;B&#8217;: 1, &#8216;D&#8217;: 1})<\/div>\n<p><strong>B<\/strong>, <strong>D<\/strong>, and <strong>F<\/strong> had <strong>negative counts<\/strong> so now their <strong>counts<\/strong> are <strong>positive<\/strong>. And it <strong>doesn\u2019t<\/strong> show the <strong>counts<\/strong> for <strong>A<\/strong>, <strong>C<\/strong>, and<strong> E<\/strong> because they are <strong>negative<\/strong>.<\/p>\n<h3>Summary<\/h3>\n<p>In this <strong>Python<\/strong> <strong>counter<\/strong> tutorial, we learned about <strong>counters<\/strong> in <strong>Python<\/strong>. We saw how to <strong>create<\/strong> them, <strong>update<\/strong> them, <strong>access elements<\/strong>, <strong>access counts<\/strong>, <strong>reassign counts<\/strong>, get the <strong>most common values<\/strong> and <strong>perform counter arithmetic<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will talk about Counter in Python. This is a class in the collections module. Other classes are defaultdict, OrderedDict and namedtuple. Let&#8217;s first discuss the concept of Python counter. What&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":76077,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[1514,1515,1516,1517,1518,1519,1520,1521],"class_list":["post-75892","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-accessing-counts-in-python-counter","tag-accessing-elements-in-python-counter","tag-counter-in-python","tag-creating-a-python-counter","tag-python-counter","tag-python-counter-arithmetic","tag-reassigning-counts-in-python-counter","tag-updating-a-counter-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Counter - Learn to create, access, and assign counters in Python - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn the full concept of counters in Python. As well as, learn to create Python counter and see how to update them, access elements, acces counts, etc.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/python-counter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Counter - Learn to create, access, and assign counters in Python - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn the full concept of counters in Python. As well as, learn to create Python counter and see how to update them, access elements, acces counts, etc.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/python-counter\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-31T08:31:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-counter.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Counter - Learn to create, access, and assign counters in Python - TechVidvan","description":"Learn the full concept of counters in Python. As well as, learn to create Python counter and see how to update them, access elements, acces counts, etc.","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:\/\/techvidvan.com\/tutorials\/python-counter\/","og_locale":"en_US","og_type":"article","og_title":"Python Counter - Learn to create, access, and assign counters in Python - TechVidvan","og_description":"Learn the full concept of counters in Python. As well as, learn to create Python counter and see how to update them, access elements, acces counts, etc.","og_url":"https:\/\/techvidvan.com\/tutorials\/python-counter\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-01-31T08:31:23+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-counter.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Python Counter &#8211; Learn to create, access, and assign counters in Python","datePublished":"2020-01-31T08:31:23+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/"},"wordCount":695,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-counter.jpg","keywords":["Accessing Counts in Python Counter","Accessing Elements in Python Counter","counter in python","Creating a Python Counter","python counter","Python Counter Arithmetic","Reassigning Counts in Python Counter","Updating a Counter in Python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/python-counter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/","url":"https:\/\/techvidvan.com\/tutorials\/python-counter\/","name":"Python Counter - Learn to create, access, and assign counters in Python - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-counter.jpg","datePublished":"2020-01-31T08:31:23+00:00","description":"Learn the full concept of counters in Python. As well as, learn to create Python counter and see how to update them, access elements, acces counts, etc.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/python-counter\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-counter.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-counter.jpg","width":802,"height":420,"caption":"python counter"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/python-counter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Python Counter &#8211; Learn to create, access, and assign counters in Python"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=75892"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75892\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/76077"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=75892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=75892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=75892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}