{"id":74692,"date":"2020-01-02T10:41:23","date_gmt":"2020-01-02T05:11:23","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=74692"},"modified":"2020-01-02T10:41:23","modified_gmt":"2020-01-02T05:11:23","slug":"python-data-structures","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/","title":{"rendered":"Python Data Structures &#8211; Learn to choose data structures wisely"},"content":{"rendered":"<p>Python is <strong>dynamically<\/strong> typed and you don\u2019t have to <strong>declare data type<\/strong> when <strong>declaring a variable<\/strong>. But Python has many data structures &#8211; <strong>collections of data<\/strong>, for different purposes.<\/p>\n<p>In this tutorial, we will discuss different types of Python data structures in brief.<\/p>\n<h3>What is Python Data Structure?<\/h3>\n<p>Python has primary data types like <strong>Boolean<\/strong>, <strong>int<\/strong>, <strong>float<\/strong>, and <strong>complex<\/strong>. It also has data structures to <strong>store <\/strong>collections of <strong>values<\/strong>.<\/p>\n<p>The data structures in Python are <strong>lists<\/strong>, <strong>tuple<\/strong>, <strong>dictionaries<\/strong>, <strong>sets<\/strong>, and <strong>strings<\/strong>. Some of them are <strong>mutable<\/strong> and the others are <strong>immutable<\/strong>.<\/p>\n<ul>\n<li>Lists<\/li>\n<li>Tuples<\/li>\n<li>Sets and frozensets<\/li>\n<li>Dictionaries<\/li>\n<li>Strings<\/li>\n<\/ul>\n<p>Let&#8217;s discuss the types of data structures in detail.<\/p>\n<h3>Types of Python Data Structures<\/h3>\n<h4>1. Lists in Python<\/h4>\n<p>Python does not have <strong>arrays<\/strong> but it has <strong>lists<\/strong>. Lists are ordered collections of <strong>items<\/strong>, they are <strong>mutable<\/strong> and <strong>heterogeneous<\/strong>.<\/p>\n<p>Let\u2019s take an example.<\/p>\n<h5>a. Creating List in Python<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries=['milk','eggs']<\/pre>\n<p>This list is called <strong>groceries<\/strong> and it has milk and eggs.<\/p>\n<p>Let\u2019s see how we will access these values.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[0]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\u2018milk\u2019<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[1]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\u2018eggs\u2019<\/div>\n<p>We can also create lists with the <strong>list() function<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums=list()\n&gt;&gt;&gt; nums.append(4)\n&gt;&gt;&gt; nums1=[]\n&gt;&gt;&gt; nums1.append(5)\n&gt;&gt;&gt; nums2=list((1,2,3,4))<\/pre>\n<h5>b. Indexing in Python<\/h5>\n<p>We access them by indexing. Indexing starts at <strong>0<\/strong>. \u2018milk\u2019 has index <strong>0<\/strong>, not <strong>1<\/strong>. And \u2018eggs\u2019 has index <strong>1<\/strong>, not <strong>2<\/strong>.<\/p>\n<p>Index 2 does not exist, so trying to access it gives us an <strong>IndexError<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[2]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Traceback (most recent call last):<br \/>\n<b>\u00a0\u00a0<\/b>File &#8220;&lt;pyshell#3&gt;&#8221;, line 1, in &lt;module&gt;<br \/>\n<b>\u00a0\u00a0\u00a0\u00a0<\/b>groceries[2]<br \/>\nIndexError: list index out of range<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[-1]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\u2018eggs\u2019<\/div>\n<h5>c. Length in Python<\/h5>\n<p>This list has 2 items, milk, and eggs.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; len(groceries)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<h5>d. Adding items in Python<\/h5>\n<p>We can <strong>append<\/strong> an item with the <strong>append() method<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries.append('bacon')\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;milk&#8217;, &#8216;eggs&#8217;, &#8216;bacon&#8217;]<\/div>\n<p>We can also <strong>extend<\/strong> the list so that it holds more values.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries.extend(['ham','bread'])\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;milk&#8217;, &#8216;eggs&#8217;, &#8216;bacon&#8217;, &#8216;ham&#8217;, &#8216;bread&#8217;]<\/div>\n<h4>e. Checking membership<\/h4>\n<p>We can check whether an item <strong>exists<\/strong> in the list. We use the <strong>\u2018in\u2019<\/strong> and <strong>\u2018not in\u2019<\/strong> operators.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'eggs' in groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'banana' in groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<h5>f. Slicing in Python<\/h5>\n<p>If you only want a <strong>part<\/strong> of the list, you can <strong>slice<\/strong> it with<strong> []<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[1:4]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;eggs&#8217;, &#8216;bacon&#8217;, &#8216;ham&#8217;]<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[-3:-1]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;bacon&#8217;, &#8216;ham&#8217;]<\/div>\n<h5>g. Modifying in Python<\/h5>\n<p>Lists are <strong>mutable<\/strong> so we can <strong>change<\/strong> its items.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;milk&#8217;, &#8216;eggs&#8217;, &#8216;bacon&#8217;, &#8216;ham&#8217;, &#8216;bread&#8217;]<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[2]='cheese'\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;milk&#8217;, &#8216;eggs&#8217;, &#8216;cheese&#8217;, &#8216;ham&#8217;, &#8216;bread&#8217;]<\/div>\n<h5>h. Deleting in Python<\/h5>\n<p>You can use the <strong>del keyword<\/strong> to delete items in a list.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; del groceries[1]\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;milk&#8217;, &#8216;cheese&#8217;, &#8216;ham&#8217;, &#8216;bread&#8217;]<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries.pop()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;bread&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries.remove('ham')\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;milk&#8217;, &#8216;cheese&#8217;]<\/div>\n<h5>i. Looping in Python<\/h5>\n<p>You can use a list in a <strong>for-loop<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for item in groceries:\n    print(item)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">milk<br \/>\ncheese<\/div>\n<h5>j. Concatenating in Python<\/h5>\n<p>We can use the <strong>+ operator<\/strong> to <strong>join two lists<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; [1,2,3]+[4,5]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[1, 2, 3, 4, 5]<\/div>\n<p>You can also <strong>multiply<\/strong> it by an <strong>integer<\/strong> to <strong>repeat<\/strong> it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; [1,2]*3<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[1, 2, 1, 2, 1, 2]<\/div>\n<h5>k. Copying in Python<\/h5>\n<p><strong>copy()<\/strong> and<strong> list()<\/strong> create shallow <strong>copies<\/strong> of a list.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries.copy()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;milk&#8217;, &#8216;cheese&#8217;]<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; list(groceries)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[&#8216;milk&#8217;, &#8216;cheese&#8217;]<\/div>\n<h5>l. Nested lists and comprehension in Python<\/h5>\n<p>You can make a list <strong>hold<\/strong> another list.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums=[1,2,[3,4],5]<\/pre>\n<p>You can also <strong>define<\/strong> it quickly.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums=[num for num in range(7)]\n&gt;&gt;&gt; nums<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">[0, 1, 2, 3, 4, 5, 6]<\/div>\n<h4>Python Tuples<\/h4>\n<p>In python data structures, Tuples are like lists, <strong>ordered collections<\/strong> of items. They can be <strong>heterogeneous<\/strong> but they are <strong>immutable<\/strong>. This means you cannot <strong>change<\/strong> their <strong>values<\/strong>.<\/p>\n<p>Let\u2019s take an example.<\/p>\n<h5>1. Creating tuples in Python<\/h5>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries=('milk','eggs')<\/pre>\n<p>This tuple is called <strong>groceries<\/strong> and it has milk and eggs.<\/p>\n<p>Let\u2019s see how we will access these values.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[0]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\u2018milk\u2019<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[1]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\u2018eggs\u2019<\/div>\n<p>We can also create tuples with the <strong>tuple() function<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums=tuple([1,2,3])\n&gt;&gt;&gt; nums<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">(1, 2, 3)<\/div>\n<h5>a. Indexing in Python<\/h5>\n<p>Like lists, we access them by <strong>indexing<\/strong>. Indexing starts at <strong>0<\/strong>. \u2018milk\u2019 has index 0 and \u2018eggs\u2019 has index <strong>1<\/strong>. Index 2 does not exist, so trying to access it gives us an <strong>IndexError<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[2]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Traceback (most recent call last):<br \/>\n<b>\u00a0\u00a0<\/b>File &#8220;&lt;pyshell#3&gt;&#8221;, line 1, in &lt;module&gt;<br \/>\n<b>\u00a0\u00a0\u00a0\u00a0<\/b>groceries[2]<br \/>\nIndexError: tuple index out of range<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[-1]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">\u2018eggs\u2019<\/div>\n<h5>b. Length in Python<\/h5>\n<p>This <strong>tuple<\/strong> has 2 items too, milk and eggs.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; len(groceries)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<h5>c. Adding items in Python<\/h5>\n<p>Tuples are <strong>immutable<\/strong> so we cannot add items to them.<\/p>\n<h5>d. Checking membership in Python<\/h5>\n<p>We can check whether an item <strong>exists<\/strong> in a tuple. We use the <strong>\u2018in\u2019<\/strong> and <strong>\u2018not in\u2019<\/strong> operators here as well.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'eggs' in groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'banana' in groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<h5>f. Slicing in Python<\/h5>\n<p>If you only want a <strong>part<\/strong> of the list, you can <strong>slice<\/strong> it with<strong> []<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[1:4]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">(&#8216;eggs&#8217;,)<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries[:]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">(&#8216;milk&#8217;, &#8216;eggs&#8217;)<\/div>\n<h5>g. Modifying in Python<\/h5>\n<p>Tuples are <strong>immutable<\/strong> so we cannot <strong>modify<\/strong> elements.<\/p>\n<h5>h. Deleting tuple in Python<\/h5>\n<p>You can <strong>delete<\/strong> a complete <strong>tuple<\/strong> but you <strong>cannot delete<\/strong> <strong>elements<\/strong> from it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; del groceries[1]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Traceback (most recent call last):<br \/>\n<b>\u00a0\u00a0<\/b>File &#8220;&lt;pyshell#50&gt;&#8221;, line 1, in &lt;module&gt;<br \/>\n<b>\u00a0\u00a0\u00a0\u00a0<\/b>del groceries[1]<br \/>\nTypeError: &#8216;tuple&#8217; object doesn&#8217;t support item deletion<\/div>\n<h5>i. Looping in Python<\/h5>\n<p>You can use a tuple as well in a<strong> for-loop<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; for item in groceries:\n  print(item)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">milk<br \/>\ncheese<\/div>\n<h5>j. Concatenating tuples in Python<\/h5>\n<p>We can use the <strong>+ operator<\/strong> to <strong>join<\/strong> two tuples.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; (1,2,3)+(4,5)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">(1, 2, 3, 4, 5)<\/div>\n<p>You can also <strong>multiply<\/strong> it by an <strong>integer<\/strong> to repeat it like in lists.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; (1,2)*3<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">(1, 2, 1, 2, 1, 2)<\/div>\n<h5>k. Copying<\/h5>\n<p>Tuples <strong>do not<\/strong> have the <strong>copy() method<\/strong>. You can use the<strong> tuple() function<\/strong> to create a tuple.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; tuple((1,2,3))<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">(1, 2, 3)<\/div>\n<h5>l. Nested tuples in Python<\/h5>\n<p>Tuples can <strong>hold<\/strong> tuples.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; nums=(1,2,(3,4),5)<\/pre>\n<p>But tuples don\u2019t have <strong>tuple comprehension<\/strong>.<\/p>\n<h4>Sets and frozensets in Python<\/h4>\n<p>In Python data structures, sets are collections of values and are <strong>unordered<\/strong>, <strong>heterogeneous<\/strong>, <strong>not indexed<\/strong> and <strong>do not<\/strong> hold <strong>duplicate elements<\/strong>.<\/p>\n<h5><strong>1. Creating<\/strong><\/h5>\n<p>You can create a set with <strong>curly braces {}<\/strong> and separating elements with <strong>commas<\/strong>.<\/p>\n<p>This is a set:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myset={1, 2.0, False}\n\n&gt;&gt;&gt; set([1, 2.0])<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{1, 2.0}<\/div>\n<p>You can also use the<strong> set() function<\/strong>.<\/p>\n<h5>2. Indexing<\/h5>\n<p>You <strong>cannot<\/strong> index or slice sets.<\/p>\n<h5>3. Length<\/h5>\n<p>You can get a set\u2019s length with the <strong>len() function<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; len(myset)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">3<\/div>\n<h5>4. Adding items<\/h5>\n<p>You can add items with the <strong>add() method<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myset.add(6)\n&gt;&gt;&gt; myset<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{False, 1, 2.0, 6}<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myset.update([7,9])\n&gt;&gt;&gt; myset<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{False, 1, 2.0, 6, 7, 9}<\/div>\n<h5>5. Deleting items<\/h5>\n<p>There are many <strong>methods<\/strong> for doing this.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myset={1,2,3,4,5,5,6,7,8,9}\n&gt;&gt;&gt; myset<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{1, 2, 3, 4, 5, 6, 7, 8, 9}<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myset.discard(5)\n&gt;&gt;&gt; myset<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{1, 2, 3, 4, 6, 7, 8, 9}<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myset.remove(6)\n&gt;&gt;&gt; myset<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{1, 2, 3, 4, 7, 8, 9}<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myset.pop()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">1<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; myset.clear()\n&gt;&gt;&gt; myset<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">set()<\/div>\n<p>You can perform operations on sets like <strong>union<\/strong>, <strong>intersection<\/strong> and <strong>set-difference<\/strong>.<\/p>\n<p>We will discuss them later.<\/p>\n<h3>frozenset in Python<\/h3>\n<p>frozensets are <strong>immutable<\/strong> sets. They can be used as <strong>keys<\/strong> for <strong>dictionaries<\/strong>&#8211; regular sets can&#8217;t be used.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; frozenset((1,2,3))<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">frozenset({1, 2, 3})<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; {'a':1, frozenset((1,2,3)):2}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{&#8216;a&#8217;: 1, frozenset({1, 2, 3}): 2}<\/div>\n<h3>Python Dictionaries<\/h3>\n<p>In python data structures, Dictionaries are <strong>unordered<\/strong> <strong>mutable<\/strong> and <strong>indexed<\/strong> <strong>collections<\/strong> of items.<\/p>\n<p>Dictionaries have <strong>key-value<\/strong> pairs. They are created in <strong>curly<\/strong> <strong>braces. <\/strong>Dictionary keys are <strong>unique<\/strong> and <strong>immutable<\/strong>.<\/p>\n<h4>1. Creating<\/h4>\n<p>You can create a <strong>dictionary<\/strong> with <strong>curly braces<\/strong> and <strong>separating keys<\/strong> and <strong>values<\/strong> by <strong>colons<\/strong> and <strong>key-value<\/strong> pairs by <strong>commas<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries={'milk':25, 'eggs':15}<\/pre>\n<p>You can also use the <strong>dict() function<\/strong> to create a dictionary.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries=dict([(1,2),(3,4)])\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{1: 2, 3: 4}<\/div>\n<h4>2. Indexing<\/h4>\n<p>You can index dictionaries with <strong>keys<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries={'milk':25, 'eggs':15}\n&gt;&gt;&gt; groceries['milk']<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">25<\/div>\n<h4>3. Accessing elements<\/h4>\n<p>Other than <strong>index<\/strong>, you can access elements in this way:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries.get('milk')<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">25<\/div>\n<h4>4. Adding items<\/h4>\n<p>You can add <strong>key-value<\/strong> pairs to <strong>dictionaries<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries['cheese']=30\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{&#8216;milk&#8217;: 25, &#8216;eggs&#8217;: 15, &#8216;cheese&#8217;: 30}<\/div>\n<h4>5. Removing items<\/h4>\n<p>We can <strong>remove<\/strong> items from dictionaries.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries={'milk':25, 'eggs':15, 'cheese':20, 'bread':15}\n&gt;&gt;&gt; groceries.pop('eggs')<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">15<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries.popitem()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">(&#8216;bread&#8217;, 15)<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; del groceries['cheese']\n&gt;&gt;&gt; groceries.clear()\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{}<\/div>\n<h4>6. Changing values<\/h4>\n<p>We can <strong>change<\/strong> values in a dictionary.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries={'milk':25, 'eggs':15, 'cheese':20, 'bread':15}\n&gt;&gt;&gt; groceries['eggs']=30<\/pre>\n<h4>7. Looping<\/h4>\n<p>We can <strong>loop<\/strong> on dictionaries with a <strong>for-loop<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for key,value in groceries.items():\n    print(key,value)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">milk 25<br \/>\neggs 30<br \/>\ncheese 20<br \/>\nbread 15<\/div>\n<h4>8. Length and membership<\/h4>\n<p>We can get a dictionary\u2019s <strong>length<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; len(groceries)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">4<\/div>\n<p>And we can test if a <strong>key<\/strong> is in a dictionary.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'bread' in groceries<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h4>9. Copying<\/h4>\n<p>We can create shallow <strong>copies<\/strong> of a dictionary.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; groceries.copy()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{&#8216;milk&#8217;: 25, &#8216;eggs&#8217;: 30, &#8216;cheese&#8217;: 20, &#8216;bread&#8217;: 15}<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dict(groceries)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{&#8216;milk&#8217;: 25, &#8216;eggs&#8217;: 30, &#8216;cheese&#8217;: 20, &#8216;bread&#8217;: 15}<\/div>\n<h4>10. Nested dictionaries and comprehension<\/h4>\n<p>Dictionaries can contain dictionaries as <strong>values<\/strong> but <strong>not as keys<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dict1={'a': {'a':1, 'b':2}, 'c':3}<\/pre>\n<p>We can also create dictionaries by <strong>comprehension<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; {num:num**2 for num in range(6)}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}<\/div>\n<h3>Python Strings<\/h3>\n<p>Python has<strong> strings<\/strong> &#8211; <strong>sequences of characters<\/strong>. We can declare them in <strong>single quotes<\/strong> or <strong>double-quotes<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'dog'<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;dog&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; \"dog\"<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;dog&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'dog\\'s gone bad'<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8220;dog&#8217;s gone bad&#8221;<\/div>\n<p>When we want to include <strong>quotes<\/strong> in a string surrounded by the same quotes, we can use <strong>escape characters<\/strong>.<\/p>\n<h4>1. Indexing<\/h4>\n<p>We can index <strong>strings<\/strong> too.<\/p>\n<h4>1.1. Positive indexing:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; text='I had a bad day today'\n&gt;&gt;&gt; text[6]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;a&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; text[-5]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;t&#8217;<\/div>\n<h4>2. Slicing<\/h4>\n<p>We can slice strings when we only want a <strong>part<\/strong> of them.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; text[2:9]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;had a b&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; text[-9:-2]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;day tod&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; text[2::3]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;h b yoy&#8217;<\/div>\n<h4>3. Deleting<\/h4>\n<p>We can delete <strong>complete strings<\/strong> but not a character or a slice.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; del text\n&gt;&gt;&gt;<\/pre>\n<h4>4. Concatenation and membership<\/h4>\n<p>We can <strong>join<\/strong> two strings with the <strong>+ operator<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'hello'+'world'<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">&#8216;helloworld&#8217;<\/div>\n<p>You can check if a <strong>value<\/strong> is in a <strong>string<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 'hell' in 'hello'<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h4>5. Length<\/h4>\n<p>We can calculate the length of a string with the<strong> len() function<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; len('hello')<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">5<\/div>\n<p>We can also format strings with the<strong> % operator<\/strong>,<strong> f-strings<\/strong> and the<strong> format() method<\/strong>.<\/p>\n<h3>Summary<\/h3>\n<p>In TechVidvan&#8217;s Python data structures article, we learned about <strong>data structures<\/strong>, <strong>lists<\/strong>, <strong>tuples<\/strong>, <strong>sets<\/strong> and <strong>frozensets<\/strong>, <strong>dictionaries<\/strong> and <strong>strings<\/strong>. These are the various types of data structures in Python. We can use them to <strong>store collections<\/strong> of <strong>values<\/strong>.<\/p>\n<p>This was all about python data structures.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python is dynamically typed and you don\u2019t have to declare data type when declaring a variable. But Python has many data structures &#8211; collections of data, for different purposes. In this tutorial, we will&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":75071,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[1162,1163,1164,1165,1166,1167],"class_list":["post-74692","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-data-structures-in-python","tag-python-data-structures","tag-python-dictionaries","tag-python-tuple","tag-types-of-data-structures-in-python","tag-what-is-python-data-structure"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Data Structures - Learn to choose data structures wisely - TechVidvan<\/title>\n<meta name=\"description\" content=\"Python Data Structures - Get ready to explore data structure in Python &amp; learn tuples, sets and frozensets, dictionaries, &amp; strings in Python with examples.\" \/>\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-data-structures\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Data Structures - Learn to choose data structures wisely - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Python Data Structures - Get ready to explore data structure in Python &amp; learn tuples, sets and frozensets, dictionaries, &amp; strings in Python with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/\" \/>\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-02T05:11:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-data-structures.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=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Data Structures - Learn to choose data structures wisely - TechVidvan","description":"Python Data Structures - Get ready to explore data structure in Python & learn tuples, sets and frozensets, dictionaries, & strings in Python with examples.","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-data-structures\/","og_locale":"en_US","og_type":"article","og_title":"Python Data Structures - Learn to choose data structures wisely - TechVidvan","og_description":"Python Data Structures - Get ready to explore data structure in Python & learn tuples, sets and frozensets, dictionaries, & strings in Python with examples.","og_url":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-01-02T05:11:23+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-data-structures.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":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Python Data Structures &#8211; Learn to choose data structures wisely","datePublished":"2020-01-02T05:11:23+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/"},"wordCount":1363,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-data-structures.jpg","keywords":["data structures in python","python data structures","python dictionaries","Python tuple","types of data structures in python","what is python data structure"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/python-data-structures\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/","url":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/","name":"Python Data Structures - Learn to choose data structures wisely - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-data-structures.jpg","datePublished":"2020-01-02T05:11:23+00:00","description":"Python Data Structures - Get ready to explore data structure in Python & learn tuples, sets and frozensets, dictionaries, & strings in Python with examples.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/python-data-structures\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-data-structures.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-data-structures.jpg","width":802,"height":420,"caption":"data structures in python"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/python-data-structures\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Python Data Structures &#8211; Learn to choose data structures wisely"}]},{"@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\/74692","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=74692"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/74692\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/75071"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=74692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=74692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=74692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}