<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Datawhiz on Medium]]></title>
        <description><![CDATA[Stories by Datawhiz on Medium]]></description>
        <link>https://medium.com/@datawhizz.26?source=rss-404c372f7bb7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Pvg1H917Aok2dSiy</url>
            <title>Stories by Datawhiz on Medium</title>
            <link>https://medium.com/@datawhizz.26?source=rss-404c372f7bb7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:18:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@datawhizz.26/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[DSA ~ Dictionary]]></title>
            <link>https://medium.com/@datawhizz.26/dsa-dictionary-06716bdff704?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/06716bdff704</guid>
            <category><![CDATA[dictionary]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sad]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Fri, 20 Mar 2026 09:52:16 GMT</pubDate>
            <atom:updated>2026-03-20T09:52:16.177Z</atom:updated>
            <content:encoded><![CDATA[<p>Python Chapter XII</p><ul><li><a href="https://www.w3schools.com/python/python_dictionaries.asp"><strong>Dictionary</strong></a> is a collection which is ordered** and changeable. No duplicate members.</li></ul><pre># Dictionary<br>my_dict= {<br>    &quot;name&quot; : &quot;John&quot;,<br>    &quot;dept&quot; : &quot;EcE&quot;,<br>    &quot;dept&quot;:&quot;cse&quot;<br>}<br><br>print(my_dict)#no error but allow only unique key:value pair that first occurence<br><br><br># Access items - using key for access the item in dictionary<br>print(my_dict[&quot;name&quot;]) # using get()<br>print(my_dict.get(&quot;name&quot;))<br><br># keys() - return all the keys in dictionary<br>print(my_dict.keys())<br><br># values() -return all the values in dictionary <br>print(my_dict.values())<br><br># items() - return each item(key:pair) values as a tuple<br>print(my_dict.items())<br><br>#check if the key in my_dict using &#39;in&#39;<br>print(&#39;name&#39; in my_dict)<br><br>#modification<br>my_dict[&quot;dept&quot;]=&#39;cse&#39;<br>print(my_dict)<br><br># The update() method will update the dictionary with the items from the given argument.<br><br># The argument must be a dictionary, or an iterable object with key:value pairs.<br><br>my_dict.update({&quot;dept&quot;:&quot;EcE&quot;})<br>print(my_dict)<br><br># Adding items in dictionary<br>my_dict[&quot;year&quot;]=2022<br>print(my_dict)<br><br># update ()<br>my_dict.update({&quot;Exp&quot;:2026})<br>print(my_dict)<br><br># remove items in dictionary - pop(),popitem(),del,clear<br>my_dict.pop(&quot;Exp&quot;)<br>print(my_dict)<br><br># The popitem() method removes the last inserted item (in versions before 3.7, a random item is removed instead)<br><br>my_dict.popitem()<br>print(my_dict)<br><br># del () - The del keyword removes the item with the specified key name<br># del my_dict[&quot;Exp&quot;]<br><br># clear() - The clear() method empties the dictionary<br># my_dict.clear()<br><br><br># loop <br>for i in my_dict:<br>    print(i) # keys<br>for i in my_dict:<br>    print(my_dict[i])#values<br># values<br>for i in my_dict.values():<br>    print(i)<br># keys()<br>for i in my_dict.keys():<br>    print(i)<br><br>#items()<br>for x,y in my_dict.items():<br>    print(x+&quot;:&quot;+y)<br>    <br>#copy dictionary <br># You cannot copy a dictionary simply by typing dict2 = dict1, because: dict2 will only be a reference to dict1, and changes made in dict1 will automatically also be made in dict2.<br><br># There are ways to make a copy, one way is to use the built-in Dictionary method copy().<br><br>fruit = {<br>    &quot;apple&quot;:1<br>}<br><br>my_dict=fruit.copy()<br>print(my_dict)<br><br># dict another way to copy <br>my_dict=dict(fruit)<br>print(my_dict)<br><br># nested dictoinary<br>myfamily = {<br>  &quot;child1&quot; : {<br>    &quot;name&quot; : &quot;Emil&quot;,<br>    &quot;year&quot; : 2004<br>  },<br>  &quot;child2&quot; : {<br>    &quot;name&quot; : &quot;Tobias&quot;,<br>    &quot;year&quot; : 2007<br>  },<br>  &quot;child3&quot; : {<br>    &quot;name&quot; : &quot;Linus&quot;,<br>    &quot;year&quot; : 2011<br>  }<br>}<br><br>#access <br>print(myfamily[&quot;child2&quot;][&quot;name&quot;])<br><br># loop<br>for x,obj in myfamily.items():<br>    print(x)<br>    for y in obj:<br>        print(y + &#39;:&#39;, obj[y])<br><br></pre><pre>#output<br>{&#39;name&#39;: &#39;John&#39;, &#39;dept&#39;: &#39;cse&#39;}<br>John<br>John<br>dict_keys([&#39;name&#39;, &#39;dept&#39;])<br>dict_values([&#39;John&#39;, &#39;cse&#39;])<br>dict_items([(&#39;name&#39;, &#39;John&#39;), (&#39;dept&#39;, &#39;cse&#39;)])<br>True<br>{&#39;name&#39;: &#39;John&#39;, &#39;dept&#39;: &#39;cse&#39;}<br>{&#39;name&#39;: &#39;John&#39;, &#39;dept&#39;: &#39;EcE&#39;}<br>{&#39;name&#39;: &#39;John&#39;, &#39;dept&#39;: &#39;EcE&#39;, &#39;year&#39;: 2022}<br>{&#39;name&#39;: &#39;John&#39;, &#39;dept&#39;: &#39;EcE&#39;, &#39;year&#39;: 2022, &#39;Exp&#39;: 2026}<br>{&#39;name&#39;: &#39;John&#39;, &#39;dept&#39;: &#39;EcE&#39;, &#39;year&#39;: 2022}<br>{&#39;name&#39;: &#39;John&#39;, &#39;dept&#39;: &#39;EcE&#39;}<br>name<br>dept<br>John<br>EcE<br>John<br>EcE<br>name<br>dept<br>name:John<br>dept:EcE<br>{&#39;apple&#39;: 1}<br>{&#39;apple&#39;: 1}<br>Tobias<br>child1<br>name: Emil<br>year: 2004<br>child2<br>name: Tobias<br>year: 2007<br>child3<br>name: Linus<br>year: 2011<br></pre><blockquote><strong>Dictionary Methods</strong></blockquote><pre># Initial dictionary<br>d = {<br>    &quot;name&quot;: &quot;Alice&quot;,<br>    &quot;age&quot;: 25,<br>    &quot;city&quot;: &quot;Chennai&quot;<br>}<br><br>print(&quot;Initial Dictionary:&quot;, d)<br>print(&quot;-&quot; * 50)<br><br># clear()<br>temp = d.copy()<br>temp.clear()<br>print(&quot;After clear():&quot;, temp)<br><br># copy()<br>d_copy = d.copy()<br>print(&quot;Copy of dictionary:&quot;, d_copy)<br><br># fromkeys()<br>keys = (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;)<br>new_dict = dict.fromkeys(keys, 0)<br>print(&quot;fromkeys():&quot;, new_dict)<br><br># get()<br>print(&quot;get(&#39;name&#39;):&quot;, d.get(&quot;name&quot;))<br>print(&quot;get(&#39;salary&#39;):&quot;, d.get(&quot;salary&quot;))          # key not present<br>print(&quot;get(&#39;salary&#39;, 0):&quot;, d.get(&quot;salary&quot;, 0))    # default value<br><br># items()<br>print(&quot;items():&quot;, list(d.items()))<br><br># keys()<br>print(&quot;keys():&quot;, list(d.keys()))<br><br># pop()<br>removed = d.pop(&quot;age&quot;)<br>print(&quot;Popped value:&quot;, removed)<br>print(&quot;After pop(&#39;age&#39;):&quot;, d)<br><br># popitem()<br>last_item = d.popitem()<br>print(&quot;popitem():&quot;, last_item)<br>print(&quot;After popitem():&quot;, d)<br><br># setdefault()<br>value = d.setdefault(&quot;country&quot;, &quot;India&quot;)<br>print(&quot;setdefault(&#39;country&#39;):&quot;, value)<br>print(&quot;After setdefault():&quot;, d)<br><br># update()<br>d.update({&quot;name&quot;: &quot;Bob&quot;, &quot;email&quot;: &quot;bob@gmail.com&quot;})<br>print(&quot;After update():&quot;, d)<br><br># values()<br>print(&quot;values():&quot;, list(d.values()))</pre><pre># output<br>Initial Dictionary: {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 25, &#39;city&#39;: &#39;Chennai&#39;}<br>--------------------------------------------------<br>After clear(): {}<br>Copy of dictionary: {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 25, &#39;city&#39;: &#39;Chennai&#39;}<br>fromkeys(): {&#39;a&#39;: 0, &#39;b&#39;: 0, &#39;c&#39;: 0}<br>get(&#39;name&#39;): Alice<br>get(&#39;salary&#39;): None<br>get(&#39;salary&#39;, 0): 0<br>items(): [(&#39;name&#39;, &#39;Alice&#39;), (&#39;age&#39;, 25), (&#39;city&#39;, &#39;Chennai&#39;)]<br>keys(): [&#39;name&#39;, &#39;age&#39;, &#39;city&#39;]<br>Popped value: 25<br>After pop(&#39;age&#39;): {&#39;name&#39;: &#39;Alice&#39;, &#39;city&#39;: &#39;Chennai&#39;}<br>popitem(): (&#39;city&#39;, &#39;Chennai&#39;)<br>After popitem(): {&#39;name&#39;: &#39;Alice&#39;}<br>setdefault(&#39;country&#39;): India<br>After setdefault(): {&#39;name&#39;: &#39;Alice&#39;, &#39;country&#39;: &#39;India&#39;}<br>After update(): {&#39;name&#39;: &#39;Bob&#39;, &#39;country&#39;: &#39;India&#39;, &#39;email&#39;: &#39;bob@gmail.com&#39;}<br>values(): [&#39;Bob&#39;, &#39;India&#39;, &#39;bob@gmail.com&#39;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ft6kRBS78pLJX_hiIZ8k_Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06716bdff704" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DSA ~ SET]]></title>
            <link>https://medium.com/@datawhizz.26/dsa-set-f96172119119?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f96172119119</guid>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[set]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Fri, 20 Mar 2026 09:50:51 GMT</pubDate>
            <atom:updated>2026-03-20T09:50:51.496Z</atom:updated>
            <content:encoded><![CDATA[<p>Python Chapter XI</p><ul><li>Sets are used to store multiple items in a single variable.</li><li><a href="https://www.w3schools.com/python/python_sets.asp"><strong>Set</strong></a> is a collection which is unordered, unchangeable*, and unindexed. No duplicate members.</li></ul><p>*Set <em>items</em> are unchangeable, but you can remove and/or add items whenever you like.</p><ul><li>*As of Python version 3.7, dictionaries are <em>ordered</em>. In Python 3.6 and earlier, dictionaries are <em>unordered</em>.</li></ul><pre>my_set={1,2,3}<br>print(my_set)<br># A set is a collection which is unordered, unchangeable*, and unindexed.<br><br>#Set items are unchangeable, <br># but you can remove items and add new items<br><br># no duplicate - true and 1 are same, false and 0 same<br><br># length<br>print(len(my_set))<br><br># different datatype allow<br>my_set={&quot;abc&quot;, 34, True, 40, &quot;male&quot;}<br>print(my_set)<br>print(type(my_set))<br><br># set constructor any datatype convert into set<br>my_list=[1,2,3]<br>my_set=set(my_list)<br>print(my_set)<br><br>#Access the set without index<br>for i in my_set:<br>    print(i)<br>#check item in set<br>print(1 in my_set)<br><br># Add item  - add()<br>my_set.add(4) # randomly the element added<br>print(my_set)<br><br># To add items from another set into the current set, use the update() method.<br><br># The update() method inserts all items from one set into another.<br><br># The update() changes the original set, and does not return a new set.<br>my_list=[5,6,7]<br>my_set.update(my_list)<br>print(my_set)<br><br>#remove item - To remove an item in a set, use the remove(), or the discard() method.<br>my_set.remove(7)<br># my_set.remove(8) - error<br># If the item to remove does not exist,<br># remove() will raise an error.<br><br>my_set.discard(8) # no error<br><br># The return value of the pop() method is the removed item. - it remove randomly so we don&#39;t know the item<br>x = my_set.pop()<br>print(x)<br><br>print(my_set)<br><br># clear and del () remove all the element in set<br>my_set.clear()<br>del my_set<br># print(my_set)<br><br># join sets - There are several ways to join two or more sets<br><br># The union() and update() methods joins all items from both sets.<br>set1 = {&quot;a&quot;, &quot;b&quot;, &quot;c&quot;}<br>set2 = {1, 2, 3}<br><br>set3 = set1.union(set2)<br>print(set3)<br><br># or <br>set1 = {&quot;a&quot;, &quot;b&quot;, &quot;c&quot;}<br>set2 = {1, 2, 3}<br><br>set3 = set1 | set2<br>print(set3)<br><br>#multiple set join<br><br>set1 = {&quot;a&quot;, &quot;b&quot;, &quot;c&quot;}<br>set2 = {1, 2, 3}<br>set3 = {&quot;John&quot;, &quot;Elena&quot;}<br>set4 = {&quot;apple&quot;, &quot;bananas&quot;, &quot;cherry&quot;}<br><br>myset = set1.union(set2, set3, set4)<br>print(myset)<br><br># The intersection() method keeps ONLY the duplicates.<br><br># The intersection() method will return a new set, that only contains the items that are present in both sets.<br><br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set3 = set1.intersection(set2)<br>print(set3)<br><br># or<br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set3 = set1 &amp; set2<br>print(set3)<br><br># The intersection_update() method will also keep ONLY the duplicates, but it will change the original set instead of returning a new set.<br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set1.intersection_update(set2)<br><br>print(set1)<br># The difference() method keeps the items from the first set that are not in the other set(s).<br><br># The difference() method will return a new set that will contain only the items from the first set that are not present in the other set.<br><br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set3 = set1.difference(set2)<br><br>print(set3)<br><br># or <br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set3 = set1.difference(set2)<br><br>print(set3)<br><br>#The - operator only allows you to join sets with sets, and not with other data types like you can with the difference() method<br><br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set1.difference_update(set2)<br><br>print(set1)<br># The symmetric_difference() method keeps all items EXCEPT the duplicates.<br># The symmetric_difference() method will keep only the elements that are NOT present in both sets.<br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set3 = set1.symmetric_difference(set2)<br><br>print(set3)<br><br># or <br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set3 = set1 ^ set2<br>print(set3)<br><br>#  not allow different datatype <br>set1 = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}<br>set2 = {&quot;google&quot;, &quot;microsoft&quot;, &quot;apple&quot;}<br><br>set1.symmetric_difference_update(set2)<br><br>print(set1)<br><br><br>#output<br>{1, 2, 3}<br>3<br>{True, 34, 40, &#39;abc&#39;, &#39;male&#39;}<br>&lt;class &#39;set&#39;&gt;<br>{1, 2, 3}<br>1<br>2<br>3<br>True<br>{1, 2, 3, 4}<br>{1, 2, 3, 4, 5, 6, 7}<br>1<br>{2, 3, 4, 5, 6}<br>{1, &#39;b&#39;, &#39;c&#39;, 2, 3, &#39;a&#39;}<br>{1, &#39;b&#39;, &#39;c&#39;, 2, 3, &#39;a&#39;}<br>{1, 2, 3, &#39;bananas&#39;, &#39;cherry&#39;, &#39;b&#39;, &#39;c&#39;, &#39;Elena&#39;, &#39;apple&#39;, &#39;a&#39;, &#39;John&#39;}<br>{&#39;apple&#39;}<br>{&#39;apple&#39;}<br>{&#39;apple&#39;}<br>{&#39;banana&#39;, &#39;cherry&#39;}<br>{&#39;banana&#39;, &#39;cherry&#39;}<br>{&#39;banana&#39;, &#39;cherry&#39;}<br>{&#39;google&#39;, &#39;banana&#39;, &#39;microsoft&#39;, &#39;cherry&#39;}<br>{&#39;google&#39;, &#39;banana&#39;, &#39;microsoft&#39;, &#39;cherry&#39;}<br>{&#39;google&#39;, &#39;microsoft&#39;, &#39;banana&#39;, &#39;cherry&#39;}<br></pre><p>SET Methods</p><pre># Initial sets<br>A = {1, 2, 3, 4}<br>B = {3, 4, 5}<br>C = {6, 7}<br><br>print(&quot;Initial A:&quot;, A)<br>print(&quot;Initial B:&quot;, B)<br>print(&quot;Initial C:&quot;, C)<br>print(&quot;-&quot; * 50)<br><br># add()<br>A.add(10)<br>print(&quot;After add(10):&quot;, A)<br><br># clear()<br>temp = {1, 2}<br>temp.clear()<br>print(&quot;After clear():&quot;, temp)<br><br># copy()<br>A_copy = A.copy()<br>print(&quot;Copy of A:&quot;, A_copy)<br><br># difference()<br>print(&quot;A.difference(B):&quot;, A.difference(B))<br><br># difference_update()<br>A_diff = A.copy()<br>A_diff.difference_update(B)<br>print(&quot;After difference_update(B):&quot;, A_diff)<br><br># discard()<br>A.discard(100)  # no error<br>print(&quot;After discard(100):&quot;, A)<br><br># intersection()<br>print(&quot;A.intersection(B):&quot;, A.intersection(B))<br><br># intersection_update()<br>A_inter = A.copy()<br>A_inter.intersection_update(B)<br>print(&quot;After intersection_update(B):&quot;, A_inter)<br><br># isdisjoint()<br>print(&quot;A.isdisjoint(C):&quot;, A.isdisjoint(C))<br><br># issubset()<br>D = {1, 2}<br>print(&quot;D.issubset(A):&quot;, D.issubset(A))<br>print(&quot;D &lt; A:&quot;, D &lt; A)<br><br># issuperset()<br>print(&quot;A.issuperset(D):&quot;, A.issuperset(D))<br>print(&quot;A &gt; D:&quot;, A &gt; D)<br><br># pop()<br>popped = D.pop()<br>print(&quot;Popped element from D:&quot;, popped)<br>print(&quot;D after pop():&quot;, D)<br><br># remove()<br>A.remove(10)<br>print(&quot;After remove(10):&quot;, A)<br><br># symmetric_difference()<br>print(&quot;A.symmetric_difference(B):&quot;, A.symmetric_difference(B))<br><br># symmetric_difference_update()<br>A_sym = A.copy()<br>A_sym.symmetric_difference_update(B)<br>print(&quot;After symmetric_difference_update(B):&quot;, A_sym)<br><br># union()<br>print(&quot;A.union(B):&quot;, A.union(B))<br><br># update()<br>A_up = A.copy()<br>A_up.update(B)<br>print(&quot;After update(B):&quot;, A_up)</pre><pre>#output<br>Initial A: {1, 2, 3, 4}<br>Initial B: {3, 4, 5}<br>Initial C: {6, 7}<br>--------------------------------------------------<br>After add(10): {1, 2, 3, 4, 10}<br>After clear(): set()<br>Copy of A: {1, 2, 3, 4, 10}<br>A.difference(B): {1, 2, 10}<br>After difference_update(B): {1, 2, 10}<br>After discard(100): {1, 2, 3, 4, 10}<br>A.intersection(B): {3, 4}<br>After intersection_update(B): {3, 4}<br>A.isdisjoint(C): True<br>D.issubset(A): True<br>D &lt; A: True<br>A.issuperset(D): True<br>A &gt; D: True<br>Popped element from D: 1<br>D after pop(): {2}<br>After remove(10): {1, 2, 3, 4}<br>A.symmetric_difference(B): {1, 2, 5}<br>After symmetric_difference_update(B): {1, 2, 5}<br>A.union(B): {1, 2, 3, 4, 5}<br>After update(B): {1, 2, 3, 4, 5}</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9b3e944f79ad812fcf526b2f5067a7c/href">https://medium.com/media/d9b3e944f79ad812fcf526b2f5067a7c/href</a></iframe><p>FrozenSet</p><pre># Creating frozensets<br>fs1 = frozenset({&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;})<br>fs2 = frozenset({&quot;banana&quot;, &quot;cherry&quot;, &quot;mango&quot;})<br>fs3 = frozenset({&quot;apple&quot;})<br><br>print(&quot;frozenset 1:&quot;, fs1)<br>print(&quot;frozenset 2:&quot;, fs2)<br>print(&quot;frozenset 3:&quot;, fs3)<br>print(&quot;Type:&quot;, type(fs1))<br>print(&quot;-&quot; * 50)<br><br># copy()<br>print(&quot;Copy of fs1:&quot;, fs1.copy())<br><br># difference()<br>print(&quot;fs1.difference(fs2):&quot;, fs1.difference(fs2))<br><br># intersection()<br>print(&quot;fs1.intersection(fs2):&quot;, fs1.intersection(fs2))<br><br># isdisjoint()<br>print(&quot;fs1.isdisjoint(fs3):&quot;, fs1.isdisjoint(fs3))<br>print(&quot;fs2.isdisjoint(fs3):&quot;, fs2.isdisjoint(fs3))<br><br># issubset()<br>print(&quot;fs3.issubset(fs1):&quot;, fs3.issubset(fs1))<br>print(&quot;fs3 &lt; fs1:&quot;, fs3 &lt; fs1)<br><br># issuperset()<br>print(&quot;fs1.issuperset(fs3):&quot;, fs1.issuperset(fs3))<br>print(&quot;fs1 &gt; fs3:&quot;, fs1 &gt; fs3)<br><br># symmetric_difference()<br>print(&quot;fs1.symmetric_difference(fs2):&quot;, fs1.symmetric_difference(fs2))<br><br># union()<br>print(&quot;fs1.union(fs2):&quot;, fs1.union(fs2))</pre><pre>frozenset 1: frozenset({&#39;banana&#39;, &#39;apple&#39;, &#39;cherry&#39;})<br>frozenset 2: frozenset({&#39;banana&#39;, &#39;cherry&#39;, &#39;mango&#39;})<br>frozenset 3: frozenset({&#39;apple&#39;})<br>Type: &lt;class &#39;frozenset&#39;&gt;<br>--------------------------------------------------<br>Copy of fs1: frozenset({&#39;banana&#39;, &#39;apple&#39;, &#39;cherry&#39;})<br>fs1.difference(fs2): frozenset({&#39;apple&#39;})<br>fs1.intersection(fs2): frozenset({&#39;banana&#39;, &#39;cherry&#39;})<br>fs1.isdisjoint(fs3): False<br>fs2.isdisjoint(fs3): True<br>fs3.issubset(fs1): True<br>fs3 &lt; fs1: True<br>fs1.issuperset(fs3): True<br>fs1 &gt; fs3: True<br>fs1.symmetric_difference(fs2): frozenset({&#39;apple&#39;, &#39;mango&#39;})<br>fs1.union(fs2): frozenset({&#39;banana&#39;, &#39;apple&#39;, &#39;cherry&#39;, &#39;mango&#39;})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ft6kRBS78pLJX_hiIZ8k_Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f96172119119" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DSA ~ Tuple]]></title>
            <link>https://medium.com/@datawhizz.26/dsa-tuple-81a8e0e317fe?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/81a8e0e317fe</guid>
            <category><![CDATA[tuples]]></category>
            <category><![CDATA[sad]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 08:01:56 GMT</pubDate>
            <atom:updated>2026-03-08T08:01:56.556Z</atom:updated>
            <content:encoded><![CDATA[<p>Python Chapter X</p><ul><li>Tuples are written with round brackets.</li></ul><p>order,allow duplicate,notchageable</p><ul><li><a href="https://www.w3schools.com/python/python_tuples.asp"><strong>Tuple</strong></a> is a collection which is ordered and unchangeable. Allows duplicate members.</li></ul><pre># Tuple creation<br>my_tuple = (&quot;apple&quot;,&quot;banana&quot;,&quot;carrot&quot;)<br>print(my_tuple)<br><br># Tuple items - ordered,unchangeable,allow duplicate, index start at  0<br><br># -- len() --<br>print(len(my_tuple))<br><br>my_tuple=&quot;apple&quot;<br><br># -- one item in tuple --<br>print(type(my_tuple))<br><br>my_tuple=(&quot;apple&quot;,)<br># with comma  in tuple<br>print(type(my_tuple))<br><br># support all the datatype  in one frame<br>my_tupe=(&quot;abc&quot;, 34, True, 40, &quot;male&quot;)<br>print(my_tuple)<br><br># tuple() constructor is make every datatype into tuple<br>list_1=[21,4,0]<br>my_tuple=tuple(list_1)<br>print(my_tuple)<br><br>#Access tuple item<br>print(my_tuple[0])<br><br># negative index<br>print(my_tuple[-1])<br><br>#Range <br>print(my_tuple[0:1])<br><br>#negative in range<br>print(my_tuple[::-1]) #reverse the tuple<br>print(my_tuple)<br><br>#checking<br>print(21 in my_tuple)<br><br># -----------------------------------------------------------------<br><br># is <br># The is operator checks if two operands refer to the exact same object in the computer&#39;s memory (i.e., they have the same memory address or identity). <br><br>a = [1, 2, 3]<br>b = [1, 2, 3]<br>c = a<br><br>print(a is b) # Output: False (a and b are different objects in memory)<br>print(a is c) # Output: True (a and c point to the same object)<br>print(a == b) # Output: True (a and b have the same value)<br><br>#in<br># The in operator checks if a value on the left side is a member of, or contained within, a collection or sequence on the right side. <br>my_list = [1, 2, 3, 4, 5]<br>value1 = 3<br>value2 = 10<br>print(value1 in my_list) # Output: True (3 is in the list)<br>print(value2 in my_list) # Output: False (10 is not in the list)<br><br>my_string = &quot;hello&quot;<br>print(&#39;h&#39; in my_string) # Output: True<br><br><br># -----------------------------------------------------------------<br><br># update  - tuple - unchangeable, or immutable<br>my_tuple = (1,2,3)<br>my_list = list(my_tuple)<br>my_list[0]=0<br>my_tuple = tuple(my_list)<br>print(my_tuple)<br><br>#Add item<br>my_list = list(my_tuple)<br>my_list.append(1) # last added<br>my_tuple = tuple(my_list)<br>print(my_tuple)<br><br># tuple + tuple<br>my_tuple1 = (1,2)<br>my_tuple2 = (3,4)<br>my_tuple1+=my_tuple2<br>print(my_tuple1)<br><br># remove - you cannot remove items in tuple instead we convert into list and then do the deletion <br>my_list = list(my_tuple)<br>del my_list[0] <br>my_tuple = tuple(my_list)<br>print(my_tuple)<br><br># Unpacking Tuple<br>my_number = (1,2,3)<br>(one,two,three)=my_number<br>print(one)<br>print(two)<br>print(three)<br><br>#The number of variables must match the number of values in the tuple, if not, you must use an asterisk to collect the remaining values as a list.<br>my_numbers=(1,2,3,4,5)<br>(one,*nums,five)=my_numbers<br>print(nums)<br>print(five)<br><br># loop<br>for i in my_numbers:<br>    print(i)<br><br># range <br>for i in range(len(my_numbers)):<br>    print(my_numbers[i])<br>    <br>i = 0<br>while i &lt; len(my_numbers):<br>  print(my_numbers[i])<br>  i = i + 1<br>  <br># join<br>my_tuple1+=my_tuple2<br>print(my_tuple1)<br><br># Multiply tuples<br>print(my_tuple*2)<br><br># --------------------------------------------------<br># Tuple methods<br># --------------------------------------------------<br><br>print(my_tuple.count(2))<br><br>print(my_tuple.index(2))</pre><pre>#output<br><br>(&#39;apple&#39;, &#39;banana&#39;, &#39;carrot&#39;)<br>3<br>&lt;class &#39;str&#39;&gt;<br>&lt;class &#39;tuple&#39;&gt;<br>(&#39;apple&#39;,)<br>(21, 4, 0)<br>21<br>0<br>(21,)<br>(0, 4, 21)<br>(21, 4, 0)<br>True<br>False<br>True<br>True<br>True<br>False<br>True<br>(0, 2, 3)<br>(0, 2, 3, 1)<br>(1, 2, 3, 4)<br>(2, 3, 1)<br>1<br>2<br>3<br>[2, 3, 4]<br>5<br>1<br>2<br>3<br>4<br>5<br>1<br>2<br>3<br>4<br>5<br>1<br>2<br>3<br>4<br>5<br>(1, 2, 3, 4, 3, 4)<br>(2, 3, 1, 2, 3, 1)<br>1<br>0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ft6kRBS78pLJX_hiIZ8k_Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81a8e0e317fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DSA ~ List]]></title>
            <link>https://medium.com/@datawhizz.26/dsa-list-4debedc22c13?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4debedc22c13</guid>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[lists]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 08:00:57 GMT</pubDate>
            <atom:updated>2026-03-08T08:00:57.623Z</atom:updated>
            <content:encoded><![CDATA[<p>Python IX</p><ul><li><strong>Data Structures</strong> is about how data can be stored in different structures.</li><li><strong>Algorithms</strong> is about how to solve different problems, often by searching through and manipulating data structures.</li><li>Understanding <strong>DSA</strong> helps you to find the best combination of <strong>Data Structures</strong> and <strong>Algorithms</strong> to create more efficient code.</li></ul><blockquote>Python has built-in support for several data structures, such as lists, dictionaries, and sets. Other data structures can be implemented using Python classes and objects, such as linked lists, stacks, queues, trees, and graphs.</blockquote><p>Lists are used to store multiple items in a single variable.</p><p>Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are <a href="https://www.w3schools.com/python/python_tuples.asp">Tuple</a>, <a href="https://www.w3schools.com/python/python_sets.asp">Set</a>, and <a href="https://www.w3schools.com/python/python_dictionaries.asp">Dictionary</a>, all with different qualities and usage.</p><p>Lists are created using square brackets:</p><ul><li><strong>List</strong> is a collection which is ordered and changeable. Allows duplicate members.</li></ul><pre>mylist=[1,&#39;a&#39;,1.0]<br># index start from 0 to many<br><br>#length - len()<br>print(len(mylist))<br><br>#Slicing <br>print(mylist[0:2])<br>print(mylist[-3:-1])# [start:stop:step] is backward<br><br>#change the item value<br><br>mylist[2]=&#39;8&#39;<br><br>print(mylist)<br><br>mylist[0:1]=[&#39;1&#39;,&#39;2&#39;]<br><br>print(mylist)<br><br>#insert item - insert(index,item)<br><br>mylist.insert(3,&#39;4&#39;)<br>print(mylist)<br><br>#append(item) <br>print(mylist.append(&#39;9&#39;))<br>print(mylist)<br><br># extend(iterable)<br># Adds all elements of an iterable (like another list) to the end.<br>thislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<br>tropical = [&quot;mango&quot;, &quot;pineapple&quot;, &quot;papaya&quot;]<br>thislist.extend(tropical)<br>print(thislist)<br><br>thislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<br>thistuple = (&quot;kiwi&quot;, &quot;orange&quot;)<br>thislist.extend(thistuple)<br>print(thislist)<br><br># remove(x) - remove first occurence of item<br>thislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<br>thislist.remove(&quot;banana&quot;)<br>print(thislist)<br><br># pop(i) - Removes and returns the element at position i.<br># Defaults to the last element.<br>thislist.pop(1)<br>print(thislist)<br><br>thislist.pop()<br>print(thislist)<br><br>fruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;kiwi&quot;, &quot;mango&quot;]<br><br># List Comprehension - simplify the loop<br># syntax - newlist = [expression for item in iterable if condition == True]<br>newlist = [x for x in fruits ]#if &quot;a&quot; in x]<br>print(newlist)<br><br># sort list - Ascending order<br>fruits.sort()<br><br># Sort Descending - sort(reverse = True)<br>fruits.sort(reverse = True)<br><br>#Customize Sort Function<br>def myfunc(n):<br>  return abs(n - 50)<br><br>thislist = [100, 50, 65, 82, 23]<br>thislist.sort(key = myfunc)<br>print(thislist)<br><br># Case Insensitive Sort<br>#  sort() - case sensitive - caps sort befoire lower<br><br>thislist = [&quot;banana&quot;, &quot;Orange&quot;, &quot;Kiwi&quot;, &quot;cherry&quot;]<br>thislist.sort(key = str.lower)<br>print(thislist)<br>thislist.reverse()<br><br># copy a List<br>list1=thislist<br>print(list1) # it i s not copy it reference the original list<br><br><br># but copy methods copy the original<br><br>thislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]<br>mylist = thislist.copy() #Another way to make a copy is to use the built-in method list().<br>print(mylist)<br><br># You can also make a copy of a list by using the : (slice) operator.<br>#mylist = thislist[:]<br>thislist.append(9)<br>print(thislist)<br><br>#join two list<br>list1 = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]<br>list2 = [1, 2, 3]<br><br>list3 = list1 + list2<br>print(list3)<br><br>fruits = [&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;]<br><br># index() Returns the index of the first element with the specified value<br>x = fruits.index(&quot;cherry&quot;)<br><br>#ouput<br>3<br>[1, &#39;a&#39;]<br>[1, &#39;a&#39;]<br>[1, &#39;a&#39;, &#39;8&#39;]<br>[&#39;1&#39;, &#39;2&#39;, &#39;a&#39;, &#39;8&#39;]<br>[&#39;1&#39;, &#39;2&#39;, &#39;a&#39;, &#39;4&#39;, &#39;8&#39;]<br>None<br>[&#39;1&#39;, &#39;2&#39;, &#39;a&#39;, &#39;4&#39;, &#39;8&#39;, &#39;9&#39;]<br>[&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;, &#39;mango&#39;, &#39;pineapple&#39;, &#39;papaya&#39;]<br>[&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;, &#39;kiwi&#39;, &#39;orange&#39;]<br>[&#39;apple&#39;, &#39;cherry&#39;]<br>[&#39;apple&#39;]<br>[]<br>[&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;, &#39;kiwi&#39;, &#39;mango&#39;]<br>[50, 65, 23, 82, 100]<br>[&#39;banana&#39;, &#39;cherry&#39;, &#39;Kiwi&#39;, &#39;Orange&#39;]<br>[&#39;Orange&#39;, &#39;Kiwi&#39;, &#39;cherry&#39;, &#39;banana&#39;]<br>[&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;]<br>[&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;, 9]</pre><blockquote><strong>List Methods</strong></blockquote><pre>list1 = [10, 20, 30, 40, 50]<br><br># access<br>print(f&quot;The first Element is : {list1[0]}&quot;)<br><br>#slice  - [start,stop,step]<br>print(f&quot;Slicing method: {list1[0:3:2]}&quot;)<br><br>&#39;&#39;&#39;<br>start → index where slicing begins<br><br>stop → index before which slicing stops (stop index is excluded)<br><br>step → how many items to skip each time<br><br>Now apply [0 : 3 : 2]:<br><br>Start at index 0 → 10<br><br>Next index = 0 + 2 = 2 → 30<br><br>Next = 2 + 2 = 4, but 4 is &gt;= stop(3) → stop.<br><br>✔ Final output:<br>[10, 30]<br><br>&#39;&#39;&#39;<br><br><br># append()<br>list1.append(&#39;0&#39;)<br><br>print(list1)<br><br>#insert()<br>list1.insert(0,&#39;0&#39;)<br>print(list1)<br><br># pop<br><br>list1.pop(0)<br><br>print(list1)<br><br>#remove<br><br>list1.remove(&#39;0&#39;)<br><br>print(list1)<br><br># sort<br>list1.sort(reverse=True)<br>print(f&quot;Desceding order: {list1}&quot;)<br>list1.sort()<br>print(f&quot;Ascending order: {list1}&quot;)<br><br>#len<br><br>print(f&quot;The length of list: {len(list1)}&quot;)<br><br>#reverse()<br><br>list1.reverse()<br>print(list1)<br><br>#del - The del keyword also removes the specified index: del thislist[0]<br><br># The del keyword can also delete the list completely. del thislist<br><br>del list1[0]<br><br>print(list1)<br><br><br># The clear() method empties the list. thislist.clear()<br>list1.clear()<br><br>print(list1) - o/p []<br><br>list_1=[1,2,2,3,2,4]<br># reverse()<br>list_1.reverse()<br>print(list_1)<br><br># count()<br>print(list_1.count(2))<br><br><br>#output<br>The first Element is : 10<br>Slicing method: [10, 30]<br>[10, 20, 30, 40, 50, &#39;0&#39;]<br>[&#39;0&#39;, 10, 20, 30, 40, 50, &#39;0&#39;]<br>[10, 20, 30, 40, 50, &#39;0&#39;]<br>[10, 20, 30, 40, 50]<br>Desceding order: [50, 40, 30, 20, 10]<br>Ascending order: [10, 20, 30, 40, 50]<br>The length of list: 5<br>[50, 40, 30, 20, 10]<br>[40, 30, 20, 10]<br>[]<br>[4, 2, 3, 2, 2, 1]<br>3</pre><h3>✅ Categories of Python Lists</h3><h3>1️⃣ List Creation</h3><p>Ways to create a list.</p><pre>a = [1, 2, 3]<br>b = list((4, 5, 6))<br>c = []</pre><h3>2️⃣ List Indexing</h3><p>Accessing elements using index numbers.</p><pre>a = [10, 20, 30]<br>print(a[0])     # 10<br>print(a[-1])    # 30</pre><h3>3️⃣ List Slicing</h3><p>Extracting a portion of a list.</p><pre>a = [1, 2, 3, 4, 5]<br>print(a[1:4])      # [2, 3, 4]<br>print(a[::2])      # [1, 3, 5]<br>print(a[::-1])     # Reverse</pre><h3>4️⃣ List Updating / Modification</h3><p>Changing elements in a list.</p><pre>a = [1, 2, 3]<br>a[1] = 20<br>print(a)  # [1, 20, 3]</pre><h3>5️⃣ List Methods (Built-in)</h3><p>Operations provided by Python.</p><p>MethodPurposeappend()Add elementextend()Add multiple elementsinsert()Insert at indexremove()Remove by valuepop()Remove by indexclear()Remove allcopy()Duplicate listcount()Count valueindex()Find indexreverse()Reverse listsort()Sort list</p><h3>6️⃣ List Deletion</h3><p>Removing elements or entire list.</p><pre>a = [1, 2, 3]<br>del a[1]<br>print(a)  # [1, 3]</pre><h3>7️⃣ List Traversing (Iteration)</h3><p>Looping through a list.</p><pre>a = [10, 20, 30]<br>for i in a:<br>    print(i)</pre><h3>8️⃣ List Comprehension</h3><p>Creating lists using expressions.</p><pre>squares = [x*x for x in range(5)]<br>print(squares)  # [0, 1, 4, 9, 16]</pre><h3>9️⃣ List Operators</h3><p>Using operators with lists.</p><p>OperatorMeaning+Concatenation*RepetitioninMembershipnot inNon-membership</p><pre>print([1, 2] + [3, 4])<br>print([1] * 3)</pre><h3>🔟 List Built-in Functions</h3><p>Functions that work on lists.</p><p>FunctionPurposelen()Lengthmax()Maximummin()Minimumsum()Sumsorted()Sorted copyany()Any Trueall()All True</p><h3>1️⃣1️⃣ Nested Lists</h3><p>Lists inside another list.</p><pre>a = [[1, 2], [3, 4]]<br>print(a[0][1])  # 2</pre><h3>1️⃣2️⃣ List Copying Techniques</h3><p>Different ways to copy lists.</p><pre>a = [1, 2, 3]<br>b = a[:]        # slicing<br>c = list(a)     # constructor</pre><h3>1️⃣3️⃣ List Comparison</h3><p>Comparing lists.</p><pre>print([1, 2] == [1, 2])  # True<br>print([1, 2] &gt; [1, 1])  # True</pre><h3>1️⃣4️⃣ List as Stack / Queue</h3><p>Using list as data structure.</p><h3>Stack (LIFO)</h3><pre>stack = []<br>stack.append(10)<br>stack.pop()</pre><h3>Queue (FIFO)</h3><pre>queue = []<br>queue.append(10)<br>queue.pop(0)</pre><h3>1️⃣5️⃣ List Memory Behavior</h3><p>Understanding references.</p><pre>a = [1, 2]<br>b = a<br>b.append(3)<br>print(a)  # [1, 2, 3]</pre><h3>🎯 Final Summary</h3><p>Python List categories include:</p><p>✔ Creation<br>✔ Indexing<br>✔ Slicing<br>✔ Updating<br>✔ Methods<br>✔ Deletion<br>✔ Traversing<br>✔ Comprehension<br>✔ Operators<br>✔ Built-in Functions<br>✔ Nested Lists<br>✔ Copying<br>✔ Comparison<br>✔ Stack/Queue Usage<br>✔ Memory Behavior</p><p>Great question 👍<br>Your list is <strong>almost complete</strong>, but for <strong>full coverage (academic + interview + DSA level)</strong>, a <strong>few important categories are still missing or usually overlooked</strong>.</p><p>Below is the <strong>FINAL, 100% COMPLETE classification of Python List categories</strong>, including what was missing 👇</p><h3>✅ Additional / Missing List Categories</h3><h3>1️⃣6️⃣ List Unpacking (Sequence Unpacking)</h3><p>Extracting values into variables.</p><pre>a = [10, 20, 30]<br>x, y, z = a<br>print(x, y, z)</pre><p>Extended unpacking:</p><pre>a = [1, 2, 3, 4, 5]<br>x, *y, z = a<br>print(x, y, z)  # 1 [2, 3, 4] 5</pre><h3>1️⃣7️⃣ Membership Testing</h3><p>Checking if an element exists.</p><pre>a = [1, 2, 3]<br>print(2 in a)      # True<br>print(5 not in a)  # True</pre><p>(Usually mentioned separately in exams)</p><h3>1️⃣8️⃣ List Sorting Variations</h3><p>Advanced sorting techniques.</p><pre>a = [(1, 3), (2, 1), (3, 2)]<br>a.sort(key=lambda x: x[1])<br>print(a)</pre><p>Also:</p><ul><li>key=</li><li>reverse=True</li></ul><h3>1️⃣9️⃣ List Filtering &amp; Mapping</h3><p>Using filter(), map() with lists.</p><pre>nums = [1, 2, 3, 4]<br>evens = list(filter(lambda x: x % 2 == 0, nums))<br>squares = list(map(lambda x: x*x, nums))</pre><h3>2️⃣0️⃣ List Conversion</h3><p>Converting other data types to list.</p><pre>list(&quot;python&quot;)        # [&#39;p&#39;,&#39;y&#39;,&#39;t&#39;,&#39;h&#39;,&#39;o&#39;,&#39;n&#39;]<br>list((1, 2, 3))       # tuple → list<br>list({1, 2, 3})       # set → list</pre><h3>2️⃣1️⃣ List Copy vs Deep Copy</h3><p>Understanding shallow vs deep copy.</p><pre>import copy<br>a = [[1, 2], [3, 4]]<br>b = copy.deepcopy(a)</pre><h3>2️⃣2️⃣ List Performance &amp; Time Complexity</h3><p>(Important for DSA &amp; interviews)</p><p>OperationTimeappend()O(1)pop()O(1)insert()O(n)remove()O(n)search (in)O(n)</p><h3>2️⃣3️⃣ List vs Other Data Structures</h3><p>Comparison category.</p><p>FeatureListTupleSetMutable✅❌❌Ordered✅✅❌Duplicate✅✅❌</p><h3>2️⃣4️⃣ List with Enumerate</h3><p>Access index + value together.</p><pre>a = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]<br>for i, v in enumerate(a):<br>    print(i, v)</pre><h3>2️⃣5️⃣ List with Zip</h3><p>Combining multiple lists.</p><pre>a = [1, 2]<br>b = [&#39;x&#39;, &#39;y&#39;]<br>print(list(zip(a, b)))</pre><h3>2️⃣6️⃣ List Immutability Illusion (Common Pitfall)</h3><p>When modifying while iterating.</p><pre>a = [1, 2, 3]<br>for i in a:<br>    a.remove(i)<br>print(a)  # Unexpected result</pre><h3>🏆 FINAL MASTER LIST — Python List Categories</h3><p>✔ Creation<br>✔ Indexing<br>✔ Slicing<br>✔ Updating<br>✔ Methods<br>✔ Deletion<br>✔ Traversing<br>✔ Comprehension<br>✔ Operators<br>✔ Built-in Functions<br>✔ Nested Lists<br>✔ Copying (Shallow/Deep)<br>✔ Comparison<br>✔ Stack / Queue<br>✔ Memory Behavior<br>✔ Unpacking<br>✔ Membership<br>✔ Sorting Variations<br>✔ Filter / Map<br>✔ Conversion<br>✔ Time Complexity<br>✔ Data Structure Comparison<br>✔ Enumerate<br>✔ Zip<br>✔ Common Pitfalls</p><blockquote><strong>List operations</strong></blockquote><h3>1. List Creation</h3><p>Ways to create a list.</p><pre># ================================<br># Using Square Brackets<br># ================================<br>a = [1, 2, 3]<br>b = [4, 5, 6]<br>c = []<br>print(a)<br>print(b)<br>print(c)<br># Output<br># [1, 2, 3]<br># [4, 5, 6]<br># []<br><br># -------------------------------<br><br># From Tuple<br>a = list((1, 2, 3))<br>print(a)<br># Output<br># [1, 2, 3]<br><br># -------------------------------<br><br># From String<br>a = list(&quot;python&quot;)<br>print(a)<br># Output<br># [&#39;p&#39;, &#39;y&#39;, &#39;t&#39;, &#39;h&#39;, &#39;o&#39;, &#39;n&#39;]<br><br># -------------------------------<br><br># From Set (order may vary)<br>a = list({1, 2, 3})<br>print(a)<br># Output<br># [1, 2, 3]<br><br># -------------------------------<br><br># From Dictionary (Keys Only)<br>a = list({&#39;a&#39;: 1, &#39;b&#39;: 2})<br>print(a)<br># Output<br># [&#39;a&#39;, &#39;b&#39;]<br><br># -------------------------------<br><br># From Dictionary Values<br>a = list({&#39;a&#39;: 1, &#39;b&#39;: 2}.values())<br>print(a)<br># Output<br># [1, 2]<br><br># -------------------------------<br><br># From Dictionary Items<br>a = list({&#39;a&#39;: 1, &#39;b&#39;: 2}.items())<br>print(a)<br># Output<br># [(&#39;a&#39;, 1), (&#39;b&#39;, 2)]<br><br># -------------------------------<br><br># Using range()<br>a = list(range(5))<br>print(a)<br># Output<br># [0, 1, 2, 3, 4]<br><br># -------------------------------<br><br># Using range(start, stop, step)<br>a = list(range(1, 10, 2))<br>print(a)<br># Output<br># [1, 3, 5, 7, 9]<br><br># -------------------------------<br><br># List Comprehension<br>a = [x for x in range(5)]<br>print(a)<br># Output<br># [0, 1, 2, 3, 4]<br><br># -------------------------------<br><br># List Comprehension with Condition<br>a = [x for x in range(10) if x % 2 == 0]<br>print(a)<br># Output<br># [0, 2, 4, 6, 8]<br><br># -------------------------------<br><br># Using map()<br>a = list(map(int, [&#39;1&#39;, &#39;2&#39;, &#39;3&#39;]))<br>print(a)<br># Output<br># [1, 2, 3]<br><br># -------------------------------<br><br># Using filter()<br>a = list(filter(lambda x: x &gt; 2, [1, 2, 3, 4]))<br>print(a)<br># Output<br># [3, 4]<br><br># -------------------------------<br><br># Using Repetition Operator (*)<br>a = [0] * 5<br>print(a)<br># Output<br># [0, 0, 0, 0, 0]<br><br># -------------------------------<br><br># Nested List<br>a = [[1, 2], [3, 4]]<br>print(a)<br># Output<br># [[1, 2], [3, 4]]<br><br># -------------------------------<br><br># Using enumerate()<br>a = list(enumerate([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]))<br>print(a)<br># Output<br># [(0, &#39;a&#39;), (1, &#39;b&#39;), (2, &#39;c&#39;)]<br><br># -------------------------------<br><br># Using zip()<br>a = list(zip([1, 2], [&#39;x&#39;, &#39;y&#39;]))<br>print(a)<br># Output<br># [(1, &#39;x&#39;), (2, &#39;y&#39;)]<br>```<br># -------------------------------<br>a = list(x*x for x in range(5))<br>print(a)<br># Output<br># [0, 1, 4, 9, 16]<br><br># -------------------------------<br>a = [1, 2, 3]<br>b = a.copy()<br>c = a[:]<br>print(b)<br>print(c)<br># Output<br># [1, 2, 3]<br># [1, 2, 3]<br></pre><h3>2. List Indexing</h3><p>Accessing elements using index numbers.</p><pre># Base List<br>lst = [10, 20, 30, 40, 50]<br>print(lst)<br># Output<br># [10, 20, 30, 40, 50]<br><br># Index reference<br># Positive →  0   1   2   3   4<br># Values   → 10  20  30  40  50<br># Negative → -5  -4  -3  -2  -1<br><br># -------------------------------<br><br>#  Positive Indexing<br>print(lst[0])<br>print(lst[2])<br># Output<br># 10<br># 30<br><br># -------------------------------<br><br>#  Negative Indexing<br>print(lst[-1])<br>print(lst[-3])<br># Output<br># 50<br># 30<br><br># -------------------------------<br><br>#  Indexing with Variable<br>i = 3<br>print(lst[i])<br># Output<br># 40<br><br># -------------------------------<br><br>#  Indexing Nested Lists<br>lst2 = [[1, 2], [3, 4], [5, 6]]<br>print(lst2[0])<br>print(lst2[1][1])<br># Output<br># [1, 2]<br># 4<br><br># -------------------------------<br><br>#  Indexing Using Loop<br>for i in range(len(lst)):<br>    print(lst[i])<br># Output<br># 10<br># 20<br># 30<br># 40<br># 50<br><br># -------------------------------<br><br>#  Indexing with enumerate()<br>for i, v in enumerate(lst):<br>    print(i, v)<br># Output<br># 0 10<br># 1 20<br># 2 30<br># 3 40<br># 4 50<br><br># -------------------------------<br><br>#  Indexing with Conditional Access<br>if lst[2] == 30:<br>    print(&quot;Found&quot;)<br># Output<br># Found<br><br># -------------------------------<br><br>#  Indexing Assignment (Update Value)<br>lst[1] = 200<br>print(lst)<br># Output<br># [10, 200, 30, 40, 50]<br><br># -------------------------------<br><br>#  Indexing Using index() Method<br>print(lst.index(40))<br># Output<br># 3<br><br># -------------------------------<br><br>#  Out of Range Index (Error Example)<br># print(lst[10])<br># Output<br># IndexError: list index out of range<br><br># -------------------------------<br><br>#  First &amp; Last Element Access<br>print(lst[0])<br>print(lst[-1])<br># Output<br># 10<br># 50<br><br># -------------------------------<br><br>#  Indexing with Expression<br>print(lst[1 + 2])<br># Output<br># 40<br>```</pre><h3>3. List Slicing</h3><p>Extracting a portion of a list.</p><pre># Sample List<br>lst = [10, 20, 30, 40, 50]<br>print(lst)<br># Output<br># [10, 20, 30, 40, 50]<br><br># Index Map<br># Index :  0   1   2   3   4<br># Value : 10  20  30  40  50<br># Neg   : -5  -4  -3  -2  -1<br><br># -------------------------------<br><br># 1. Basic Slicing [start:stop]<br>print(lst[1:4])<br># Output<br># [20, 30, 40]<br><br># -------------------------------<br><br># 2. Start Only [start:]<br>print(lst[2:])<br># Output<br># [30, 40, 50]<br><br># -------------------------------<br><br># 3. Stop Only [:stop]<br>print(lst[:3])<br># Output<br># [10, 20, 30]<br><br># -------------------------------<br><br># 4. Full Slice [:]<br>print(lst[:])<br># Output<br># [10, 20, 30, 40, 50]<br><br># -------------------------------<br><br># 5. Slicing with Step [start:stop:step]<br>print(lst[0:5:2])<br># Output<br># [10, 30, 50]<br><br># -------------------------------<br><br># 6. Step Only [::step]<br>print(lst[::2])<br># Output<br># [10, 30, 50]<br><br># -------------------------------<br><br># 7. Negative Step (Reverse)<br>print(lst[::-1])<br># Output<br># [50, 40, 30, 20, 10]<br><br># -------------------------------<br><br># 8. Reverse with Range [-1:-6:-1]<br>print(lst[-1:-6:-1])<br># Output<br># [50, 40, 30, 20, 10]<br><br># -------------------------------<br><br># 9. Negative Index Slicing<br>print(lst[-4:-1])<br># Output<br># [20, 30, 40]<br><br># -------------------------------<br><br># 10. Mixed Positive &amp; Negative Index<br>print(lst[1:-1])<br># Output<br># [20, 30, 40]<br><br># -------------------------------<br><br># 11. Slicing with Out-of-Range Index<br>print(lst[1:100])<br># Output<br># [20, 30, 40, 50]<br><br># -------------------------------<br><br># 12. Slicing for Copying List<br>copy_lst = lst[:]<br>print(copy_lst)<br># Output<br># [10, 20, 30, 40, 50]<br><br># -------------------------------<br><br># 13. Slicing for Updating (Assignment)<br>lst[1:3] = [200, 300]<br>print(lst)<br># Output<br># [10, 200, 300, 40, 50]<br><br># -------------------------------<br><br># 14. Deleting Elements using Slicing<br>del lst[1:3]<br>print(lst)<br># Output<br># [10, 40, 50]<br><br># -------------------------------<br><br># 15. Slicing with Empty Result<br>print(lst[3:1])<br># Output<br># []<br><br># -------------------------------<br><br># IMPORTANT RULES<br># stop index is excluded<br># default start = 0<br># default stop = len(list)<br># default step = 1<br># slicing never raises IndexError<br>```</pre><h3>4. List Updating / Modification</h3><p>Changing elements in a list.</p><pre># Sample List<br>lst = [10, 20, 30, 40, 50]<br>print(lst)<br># Output<br># [10, 20, 30, 40, 50]<br><br># -------------------------------<br><br># 1. Update Single Element (Index Assignment)<br>lst[1] = 200<br>print(lst)<br># Output<br># [10, 200, 30, 40, 50]<br><br># -------------------------------<br><br># 2. Update Using Negative Index<br>lst[-1] = 500<br>print(lst)<br># Output<br># [10, 200, 30, 40, 500]<br><br># -------------------------------<br><br># 3. Update Multiple Elements (Slice Assignment)<br>lst[1:3] = [100, 300]<br>print(lst)<br># Output<br># [10, 100, 300, 40, 500]<br><br># -------------------------------<br><br># 4. Replace Slice with Different Size<br>lst[1:3] = [99]<br>print(lst)<br># Output<br># [10, 99, 40, 500]<br><br># -------------------------------<br><br># 5. Insert Elements using Slice<br>lst[2:2] = [25, 35]<br>print(lst)<br># Output<br># [10, 99, 25, 35, 40, 500]<br><br># -------------------------------<br><br># 6. Update Using Loop<br>for i in range(len(lst)):<br>    lst[i] += 1<br>print(lst)<br># Output<br># [11, 100, 26, 36, 41, 501]<br><br># -------------------------------<br><br># 7. Conditional Update<br>for i in range(len(lst)):<br>    if lst[i] &gt; 100:<br>        lst[i] = 0<br>print(lst)<br># Output<br># [11, 100, 26, 36, 41, 0]<br><br># -------------------------------<br><br># 8. Update Nested List<br>lst_nested = [[1, 2], [3, 4]]<br>lst_nested[0][1] = 20<br>print(lst_nested)<br># Output<br># [[1, 20], [3, 4]]<br><br># -------------------------------<br><br># 9. Update Using List Comprehension<br>lst2 = [1, 2, 3, 4]<br>lst2 = [x * 10 for x in lst2]<br>print(lst2)<br># Output<br># [10, 20, 30, 40]<br><br># -------------------------------<br><br># 10. Update Using enumerate()<br>lst3 = [5, 10, 15]<br>for i, v in enumerate(lst3):<br>    lst3[i] = v * 2<br>print(lst3)<br># Output<br># [10, 20, 30]<br><br># -------------------------------<br><br># 11. Append Element<br>lst = [10, 200, 30, 40, 50]<br>lst.append(60)<br>print(lst)<br># Output<br># [10, 200, 30, 40, 50, 60]<br><br># -------------------------------<br><br># 12. Extend List (Bulk Update)<br>lst.extend([70, 80])<br>print(lst)<br># Output<br># [10, 200, 30, 40, 50, 60, 70, 80]<br><br># -------------------------------<br><br># 13. Insert Element at Index<br>lst.insert(1, 999)<br>print(lst)<br># Output<br># [10, 999, 200, 30, 40, 50, 60, 70, 80]<br><br># -------------------------------</pre><h3>5. List Methods (Built-in)</h3><p>Operations provided by Python.</p><pre>## Sample List<br>lst = [10, 20, 30, 20, 40]<br><br>--------------------------------------------------<br><br>## 1. append()<br>Adds one element at the end of the list.<br><br>Code:<br>lst.append(50)<br>print(lst)<br><br>Output:<br>[10, 20, 30, 20, 40, 50]<br><br>--------------------------------------------------<br><br>## 2. extend()<br>Adds elements of another iterable.<br><br>Code:<br>lst.extend([60, 70])<br>print(lst)<br><br>Output:<br>[10, 20, 30, 20, 40, 50, 60, 70]<br><br>--------------------------------------------------<br><br>## 3. insert()<br>Inserts element at a specified index.<br><br>Code:<br>lst.insert(2, 99)<br>print(lst)<br><br>Output:<br>[10, 20, 99, 30, 20, 40, 50, 60, 70]<br><br>--------------------------------------------------<br><br>## 4. remove()<br>Removes the first occurrence of a value.<br><br>Code:<br>lst.remove(20)<br>print(lst)<br><br>Output:<br>[10, 99, 30, 20, 40, 50, 60, 70]<br><br>--------------------------------------------------<br><br>## 5. pop()<br>Removes and returns element (default last).<br><br>Code:<br>x = lst.pop()<br>print(x)<br>print(lst)<br><br>Output:<br>70<br>[10, 99, 30, 20, 40, 50, 60]<br><br>--------------------------------------------------<br><br>## 6. clear()<br>Removes all elements.<br><br>Code:<br>lst.clear()<br>print(lst)<br><br>Output:<br>[]<br><br>--------------------------------------------------<br><br>## 7. copy()<br>Returns a shallow copy of the list.<br><br>Code:<br>lst = [1, 2, 3]<br>new_lst = lst.copy()<br>print(new_lst)<br><br>Output:<br>[1, 2, 3]<br><br>--------------------------------------------------<br><br>## 8. count()<br>Counts occurrences of a value.<br><br>Code:<br>lst = [1, 2, 2, 3, 2]<br>print(lst.count(2))<br><br>Output:<br>3<br><br>--------------------------------------------------<br><br>## 9. index()<br>Returns index of first occurrence.<br><br>Code:<br>lst = [10, 20, 30, 40]<br>print(lst.index(30))<br><br>Output:<br>2<br><br>--------------------------------------------------<br><br>## 10. reverse()<br>Reverses the list in place.<br><br>Code:<br>lst = [1, 2, 3]<br>lst.reverse()<br>print(lst)<br><br>Output:<br>[3, 2, 1]<br><br>--------------------------------------------------<br><br>## 11. sort()<br>Sorts the list.<br><br>Ascending Order:<br>Code:<br>lst = [4, 1, 3, 2]<br>lst.sort()<br>print(lst)<br><br>Output:<br>[1, 2, 3, 4]<br><br>Descending Order:<br>Code:<br>lst.sort(reverse=True)<br>print(lst)<br><br>Output:<br>[4, 3, 2, 1]<br><br>--------------------------------------------------</pre><h3>6. List Deletion</h3><p>Removing elements or entire list.</p><pre>## Sample List<br>lst = [10, 20, 30, 40, 50]<br><br>--------------------------------------------------<br><br>## 1. del with Index<br>Deletes element at a specific index.<br><br>Code:<br>del lst[1]<br>print(lst)<br><br>Output:<br>[10, 30, 40, 50]<br><br>--------------------------------------------------<br><br>## 2. del with Slice<br>Deletes multiple elements.<br><br>Code:<br>lst = [10, 20, 30, 40, 50]<br>del lst[1:4]<br>print(lst)<br><br>Output:<br>[10, 50]<br><br>--------------------------------------------------<br><br>## 3. pop()<br>Deletes element by index and returns it.<br><br>Code:<br>lst = [10, 20, 30]<br>x = lst.pop(1)<br>print(x)<br>print(lst)<br><br>Output:<br>20<br>[10, 30]<br><br>--------------------------------------------------<br><br>## 4. remove()<br>Deletes first occurrence of a value.<br><br>Code:<br>lst = [10, 20, 20, 30]<br>lst.remove(20)<br>print(lst)<br><br>Output:<br>[10, 20, 30]<br><br>--------------------------------------------------<br><br>## 5. clear()<br>Deletes all elements.<br><br>Code:<br>lst = [10, 20, 30]<br>lst.clear()<br>print(lst)<br><br>Output:<br>[]<br><br>--------------------------------------------------<br><br># Summary<br>del → removes by index or slice<br>pop() → removes by index (returns value)<br>remove() → removes by value<br>clear() → removes everything</pre><h3>7. List Traversing (Iteration)</h3><p>Looping through a list.</p><pre>## Sample List<br>lst = [10, 20, 30, 40]<br><br>--------------------------------------------------<br><br>## 1. Simple for loop<br>Iterates value by value.<br><br>Code:<br>for x in lst:<br>    print(x)<br><br>Output:<br>10<br>20<br>30<br>40<br><br>--------------------------------------------------<br><br>## 2. for loop with index (range)<br>Iterates using index.<br><br>Code:<br>for i in range(len(lst)):<br>    print(lst[i])<br><br>Output:<br>10<br>20<br>30<br>40<br><br>--------------------------------------------------<br><br>## 3. for loop with enumerate()<br>Gets index and value.<br><br>Code:<br>for i, v in enumerate(lst):<br>    print(i, v)<br><br>Output:<br>0 10<br>1 20<br>2 30<br>3 40<br><br>--------------------------------------------------<br><br>## 4. while loop<br>Traversal using condition.<br><br>Code:<br>i = 0<br>while i &lt; len(lst):<br>    print(lst[i])<br>    i += 1<br><br>Output:<br>10<br>20<br>30<br>40<br><br>--------------------------------------------------<br><br>## 5. List comprehension (Traversal + Operation)<br>Traverses and creates new list.<br><br>Code:<br>new_lst = [x * 2 for x in lst]<br>print(new_lst)<br><br>Output:<br>[20, 40, 60, 80]<br><br>--------------------------------------------------<br><br>## 6. map()<br>Applies function to each element.<br><br>Code:<br>new_lst = list(map(lambda x: x + 1, lst))<br>print(new_lst)<br><br>Output:<br>[11, 21, 31, 41]<br><br>--------------------------------------------------<br><br>## 7. filter()<br>Traverses and filters elements.<br><br>Code:<br>new_lst = list(filter(lambda x: x &gt; 20, lst))<br>print(new_lst)<br><br>Output:<br>[30, 40]<br><br>--------------------------------------------------<br><br>## 8. reversed()<br>Traverses list in reverse order.<br><br>Code:<br>for x in reversed(lst):<br>    print(x)<br><br>Output:<br>40<br>30<br>20<br>10<br><br>--------------------------------------------------<br><br>## 9. Using slicing (reverse traversal)<br>Traverses using slicing.<br><br>Code:<br>for x in lst[::-1]:<br>    print(x)<br><br>Output:<br>40<br>30<br>20<br>10<br><br>--------------------------------------------------<br><br>## 10. Using iterator (iter() and next())<br>Manual traversal.<br><br>Code:<br>it = iter(lst)<br>print(next(it))<br>print(next(it))<br>print(next(it))<br>print(next(it))<br><br>Output:<br>10<br>20<br>30<br>40<br><br>--------------------------------------------------<br># Summary<br>Total Traversing Techniques = 10<br>for, while, enumerate, map, filter, comprehension, reversed, slicing, iterator</pre><h3>8. List Comprehension</h3><p>Creating lists using expressions.</p><pre># Python List Comprehension (Total: 8)<br><br>## Sample Data<br>nums = [1, 2, 3, 4, 5]<br><br>--------------------------------------------------<br><br>## 1. Basic List Comprehension<br>Creates a list using expression.<br><br>Code:<br>lst = [x for x in nums]<br>print(lst)<br><br>Output:<br>[1, 2, 3, 4, 5]<br><br>--------------------------------------------------<br><br>## 2. List Comprehension with Expression<br>Applies operation on each element.<br><br>Code:<br>lst = [x * x for x in nums]<br>print(lst)<br><br>Output:<br>[1, 4, 9, 16, 25]<br><br>--------------------------------------------------<br><br>## 3. List Comprehension with if Condition<br>Filters elements.<br><br>Code:<br>lst = [x for x in nums if x % 2 == 0]<br>print(lst)<br><br>Output:<br>[2, 4]<br><br>--------------------------------------------------<br><br>## 4. if–else in List Comprehension<br>Conditional expression.<br><br>Code:<br>lst = [&quot;even&quot; if x % 2 == 0 else &quot;odd&quot; for x in nums]<br>print(lst)<br><br>Output:<br>[&#39;odd&#39;, &#39;even&#39;, &#39;odd&#39;, &#39;even&#39;, &#39;odd&#39;]<br><br>--------------------------------------------------<br><br>## 5. Nested List Comprehension<br>Loops inside loop.<br><br>Code:<br>matrix = [[1, 2], [3, 4]]<br>lst = [x for row in matrix for x in row]<br>print(lst)<br><br>Output:<br>[1, 2, 3, 4]<br><br>--------------------------------------------------<br><br>## 6. List Comprehension with range()<br>Generates numbers.<br><br>Code:<br>lst = [x for x in range(5)]<br>print(lst)<br><br>Output:<br>[0, 1, 2, 3, 4]<br><br>--------------------------------------------------<br><br>## 7. List Comprehension with Function Call<br>Uses function inside expression.<br><br>Code:<br>lst = [len(x) for x in [&quot;python&quot;, &quot;java&quot;, &quot;c&quot;]]<br>print(lst)<br><br>Output:<br>[6, 4, 1]<br><br>--------------------------------------------------<br><br>## 8. List Comprehension with Multiple Conditions<br>Applies more than one condition.<br><br>Code:<br>lst = [x for x in range(20) if x % 2 == 0 if x % 3 == 0]<br>print(lst)<br><br>Output:<br>[0, 6, 12, 18]<br><br>--------------------------------------------------<br><br># Summary<br>Total List Comprehension Types = 8<br>Used for compact, readable, and efficient list creation</pre><h3>9. List Operators</h3><p>Using operators with lists.</p><pre># Python List Operators (Total: 6)<br><br>## Sample Lists<br>a = [1, 2, 3]<br>b = [4, 5]<br><br>--------------------------------------------------<br><br>## 1. +  (Concatenation Operator)<br>Joins two lists.<br><br>Code:<br>print(a + b)<br><br>Output:<br>[1, 2, 3, 4, 5]<br><br>--------------------------------------------------<br><br>## 2. *  (Repetition Operator)<br>Repeats list elements.<br><br>Code:<br>print(a * 2)<br><br>Output:<br>[1, 2, 3, 1, 2, 3]<br><br>--------------------------------------------------<br><br>## 3. in  (Membership Operator)<br>Checks if element exists.<br><br>Code:<br>print(2 in a)<br><br>Output:<br>True<br><br>--------------------------------------------------<br><br>## 4. not in  (Non-Membership Operator)<br>Checks if element does not exist.<br><br>Code:<br>print(5 not in a)<br><br>Output:<br>True<br><br>--------------------------------------------------<br><br>## 5. ==  (Equality Operator)<br>Checks if two lists are equal (value &amp; order).<br><br>Code:<br>print([1, 2] == [1, 2])<br>print([1, 2] == [2, 1])<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br>## 6. !=  (Not Equal Operator)<br>Checks if lists are different.<br><br>Code:<br>print([1, 2] != [2, 1])<br><br>Output:<br>True<br><br>--------------------------------------------------<br><br># Summary<br>Total List Operators = 6<br>Operators work element-wise or on whole lists</pre><h3>10. List Built-in Functions</h3><p>Functions that work on lists.</p><pre># Python List Built-in Functions (Total: 11)<br><br>## Sample List<br>lst = [10, 20, 30, 40]<br><br>--------------------------------------------------<br><br>## 1. len()<br>Returns number of elements.<br><br>Code:<br>print(len(lst))<br><br>Output:<br>4<br><br>--------------------------------------------------<br><br>## 2. max()<br>Returns largest element.<br><br>Code:<br>print(max(lst))<br><br>Output:<br>40<br><br>--------------------------------------------------<br><br>## 3. min()<br>Returns smallest element.<br><br>Code:<br>print(min(lst))<br><br>Output:<br>10<br><br>--------------------------------------------------<br><br>## 4. sum()<br>Returns sum of elements.<br><br>Code:<br>print(sum(lst))<br><br>Output:<br>100<br><br>--------------------------------------------------<br><br>## 5. sorted()<br>Returns a new sorted list.<br><br>Code:<br>print(sorted(lst))<br><br>Output:<br>[10, 20, 30, 40]<br><br>--------------------------------------------------<br><br>## 6. any()<br>Returns True if any element is True.<br><br>Code:<br>print(any([0, 0, 5]))<br><br>Output:<br>True<br><br>--------------------------------------------------<br><br>## 7. all()<br>Returns True if all elements are True.<br><br>Code:<br>print(all([1, 2, 3]))<br><br>Output:<br>True<br><br>--------------------------------------------------<br><br>## 8. enumerate()<br>Returns index-value pairs.<br><br>Code:<br>print(list(enumerate(lst)))<br><br>Output:<br>[(0, 10), (1, 20), (2, 30), (3, 40)]<br><br>--------------------------------------------------<br><br>## 9. zip()<br>Combines multiple lists.<br><br>Code:<br>a = [1, 2]<br>b = [&#39;x&#39;, &#39;y&#39;]<br>print(list(zip(a, b)))<br><br>Output:<br>[(1, &#39;x&#39;), (2, &#39;y&#39;)]<br><br>--------------------------------------------------<br><br>## 10. reversed()<br>Returns reversed iterator.<br><br>Code:<br>print(list(reversed(lst)))<br><br>Output:<br>[40, 30, 20, 10]<br><br>--------------------------------------------------<br><br>## 11. map()<br>Applies function to each element.<br><br>Code:<br>print(list(map(lambda x: x * 2, lst)))<br><br>Output:<br>[20, 40, 60, 80]<br><br>--------------------------------------------------<br><br># Summary<br>Total List Built-in Functions = 11<br>These functions do NOT modify the original list (except via returned result)</pre><h3>11. Nested Lists</h3><p>Lists inside another list.</p><pre># Python Nested Lists (Total: 8)<br><br>## Sample Nested List<br>lst = [[10, 20], [30, 40], [50, 60]]<br><br>--------------------------------------------------<br><br>## 1. Creating a Nested List<br>A list inside another list.<br><br>Code:<br>lst = [[1, 2], [3, 4]]<br>print(lst)<br><br>Output:<br>[[1, 2], [3, 4]]<br><br>--------------------------------------------------<br><br>## 2. Accessing Inner List<br>Access whole sub-list.<br><br>Code:<br>print(lst[0])<br><br>Output:<br>[1, 2]<br><br>--------------------------------------------------<br><br>## 3. Accessing Nested Elements<br>Access element inside sub-list.<br><br>Code:<br>print(lst[1][0])<br><br>Output:<br>3<br><br>--------------------------------------------------<br><br>## 4. Updating Nested Element<br>Modify inner list value.<br><br>Code:<br>lst[0][1] = 99<br>print(lst)<br><br>Output:<br>[[1, 99], [3, 4]]<br><br>--------------------------------------------------<br><br>## 5. Traversing Nested List (for loop)<br>Iterate through nested list.<br><br>Code:<br>for row in lst:<br>    for val in row:<br>        print(val)<br><br>Output:<br>1<br>99<br>3<br>4<br><br>--------------------------------------------------<br><br>## 6. Nested List Comprehension<br>Flatten nested list.<br><br>Code:<br>flat = [x for row in lst for x in row]<br>print(flat)<br><br>Output:<br>[1, 99, 3, 4]<br><br>--------------------------------------------------<br><br>## 7. Matrix Style Nested List<br>2D list representation.<br><br>Code:<br>matrix = [<br>    [1, 2, 3],<br>    [4, 5, 6]<br>]<br>print(matrix[1][2])<br><br>Output:<br>6<br><br>--------------------------------------------------<br><br>## 8. Deleting Nested Elements<br>Remove inner element.<br><br>Code:<br>del lst[1][0]<br>print(lst)<br><br>Output:<br>[[1, 99], [4]]<br><br>--------------------------------------------------<br><br># Summary<br>Total Nested List Concepts = 8<br>Used for matrices, tables, and multi-dimensional data</pre><h3>12. List Copying Techniques</h3><p>Different ways to copy lists.</p><pre># Python List Copying Techniques (Total: 5)<br><br>## Sample List<br>lst = [1, 2, 3, [4, 5]]<br><br>--------------------------------------------------<br><br>## 1. Assignment (Reference Copy)<br>Both variables point to same list.<br><br>Code:<br>a = lst<br>a[0] = 10<br>print(lst)<br>print(a)<br><br>Output:<br>[10, 2, 3, [4, 5]]<br>[10, 2, 3, [4, 5]]<br><br>--------------------------------------------------<br><br>## 2. Shallow Copy Using Slicing [:]<br>Creates a new outer list but inner lists are still referenced.<br><br>Code:<br>a = lst[:]<br>a[0] = 100<br>a[3][0] = 40<br>print(lst)<br>print(a)<br><br>Output:<br>[10, 2, 3, [40, 5]]<br>[100, 2, 3, [40, 5]]<br><br>--------------------------------------------------<br><br>## 3. Shallow Copy Using list()<br>Similar to slicing.<br><br>Code:<br>a = list(lst)<br>a[1] = 200<br>a[3][1] = 50<br>print(lst)<br>print(a)<br><br>Output:<br>[10, 2, 3, [40, 50]]<br>[10, 200, 3, [40, 50]]<br><br>--------------------------------------------------<br><br>## 4. Shallow Copy Using copy.copy()<br>Needs import copy. Outer list copied, inner list referenced.<br><br>Code:<br>import copy<br>a = copy.copy(lst)<br>a[0] = 500<br>a[3][0] = 60<br>print(lst)<br>print(a)<br><br>Output:<br>[10, 2, 3, [60, 50]]<br>[500, 2, 3, [60, 50]]<br><br>--------------------------------------------------<br><br>## 5. Deep Copy Using copy.deepcopy()<br>Copies outer and inner lists completely.<br><br>Code:<br>a = copy.deepcopy(lst)<br>a[0] = 700<br>a[3][1] = 80<br>print(lst)<br>print(a)<br><br>Output:<br>[10, 2, 3, [60, 50]]<br>[700, 2, 3, [60, 80]]<br><br>--------------------------------------------------<br><br># Summary<br>Total List Copying Techniques = 5<br>- Assignment → reference only<br>- Shallow copy → outer list copied, inner lists shared<br>- Deep copy → fully independent copy</pre><h3>13. List Comparison</h3><p>Comparing lists.</p><pre># Python List Comparison (Total: 6)<br><br>## Sample Lists<br>a = [1, 2, 3]<br>b = [1, 2, 3]<br>c = [3, 2, 1]<br><br>--------------------------------------------------<br><br>## 1. Equality (==)<br>Checks if lists have same elements in same order.<br><br>Code:<br>print(a == b)<br>print(a == c)<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br>## 2. Inequality (!=)<br>Checks if lists are different.<br><br>Code:<br>print(a != b)<br>print(a != c)<br><br>Output:<br>False<br>True<br><br>--------------------------------------------------<br><br>## 3. Greater Than (&gt;)<br>Compares lists lexicographically (element by element).<br><br>Code:<br>print([2, 3] &gt; [1, 5])<br>print([1, 2] &gt; [1, 3])<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br>## 4. Less Than (&lt;)<br>Compares lists lexicographically.<br><br>Code:<br>print([1, 2] &lt; [1, 3])<br>print([2, 3] &lt; [1, 5])<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br>## 5. Greater or Equal (&gt;=)<br><br>Code:<br>print([1, 2, 3] &gt;= [1, 2, 3])<br>print([2, 3] &gt;= [1, 5])<br><br>Output:<br>True<br>True<br><br>--------------------------------------------------<br><br>## 6. Less or Equal (&lt;=)<br><br>Code:<br>print([1, 2, 3] &lt;= [1, 2, 3])<br>print([1, 2] &lt;= [1, 1, 5])<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br># Summary<br>Total List Comparison Techniques = 6<br>Comparison is element-wise (lexicographical) and order matters</pre><h3>14. List as Stack / Queue</h3><p>Using list as data structure.</p><h3>Stack (LIFO) and Queue (FIFO)</h3><pre># Python List as Stack / Queue (Total: 6)<br><br>## Sample List<br>lst = [10, 20, 30]<br><br>--------------------------------------------------<br><br># STACK (LIFO)<br><br>## 1. Stack Push (append)<br>Add element at the top.<br><br>Code:<br>stack = [10, 20, 30]<br>stack.append(40)<br>print(stack)<br><br>Output:<br>[10, 20, 30, 40]<br><br>--------------------------------------------------<br><br>## 2. Stack Pop<br>Remove element from the top.<br><br>Code:<br>x = stack.pop()<br>print(x)<br>print(stack)<br><br>Output:<br>40<br>[10, 20, 30]<br><br>--------------------------------------------------<br><br>## 3. Stack Peek (Access top element)<br>Access last element without removing.<br><br>Code:<br>print(stack[-1])<br><br>Output:<br>30<br><br>--------------------------------------------------<br><br># QUEUE (FIFO)<br><br>## 4. Queue Enqueue (append)<br>Add element at the end.<br><br>Code:<br>queue = [10, 20, 30]<br>queue.append(40)<br>print(queue)<br><br>Output:<br>[10, 20, 30, 40]<br><br>--------------------------------------------------<br><br>## 5. Queue Dequeue (pop(0))<br>Remove element from the front.<br><br>Code:<br>x = queue.pop(0)<br>print(x)<br>print(queue)<br><br>Output:<br>10<br>[20, 30, 40]<br><br>--------------------------------------------------<br><br>## 6. Queue Front / Peek<br>Access first element without removing.<br><br>Code:<br>print(queue[0])<br><br>Output:<br>20<br><br>--------------------------------------------------<br><br># Summary<br>Total Stack / Queue Operations = 6<br>Stack → LIFO → append(), pop(), peek()<br>Queue → FIFO → append(), pop(0), peek()</pre><h3>15. List Memory Behavior</h3><p>Understanding references.</p><pre># Python List Memory Behavior (Total: 6)<br><br>## 1. Lists are Mutable<br>Changes in list modify the same object in memory.<br><br>Code:<br>lst = [1, 2, 3]<br>print(id(lst))<br>lst[0] = 10<br>print(lst)<br>print(id(lst))<br><br>Output:<br>140139205067520  # example id<br>[10, 2, 3]<br>140139205067520   # id unchanged<br><br>--------------------------------------------------<br><br>## 2. Assignment Copies Reference<br>Assigning list to another variable points to same memory.<br><br>Code:<br>a = [1, 2, 3]<br>b = a<br>b[0] = 99<br>print(a)<br>print(b)<br><br>Output:<br>[99, 2, 3]<br>[99, 2, 3]<br><br>--------------------------------------------------<br><br>## 3. Shallow Copy (slice / list() / copy.copy())<br>Outer list copied, inner objects shared.<br><br>Code:<br>import copy<br>lst = [[1, 2], [3, 4]]<br>shallow = lst[:]<br>shallow[0][0] = 10<br>print(lst)<br>print(shallow)<br><br>Output:<br>[[10, 2], [3, 4]]<br>[[10, 2], [3, 4]]<br><br>--------------------------------------------------<br><br>## 4. Deep Copy (copy.deepcopy())<br>Copies outer and inner lists completely.<br><br>Code:<br>deep = copy.deepcopy(lst)<br>deep[0][1] = 99<br>print(lst)<br>print(deep)<br><br>Output:<br>[[10, 2], [3, 4]]<br>[[10, 99], [3, 4]]<br><br>--------------------------------------------------<br><br>## 5. Memory Addresses (id)<br>Shows memory location of list and elements.<br><br>Code:<br>lst = [1, 2, 3]<br>for x in lst:<br>    print(x, id(x))<br>print(&quot;List id:&quot;, id(lst))<br><br>Output:<br>1 9783360<br>2 9783392<br>3 9783424<br>List id: 140139205067520  # example<br><br>--------------------------------------------------<br><br>## 6. Copying vs Reference Behavior Summary<br>- `=` → reference copy (same object)<br>- `[:]` or `list()` → shallow copy (outer copied, inner shared)<br>- `copy.deepcopy()` → deep copy (completely independent)<br><br></pre><h3>16. List Unpacking (Sequence Unpacking)</h3><p>Extracting values into variables.</p><pre># Python List Unpacking (Total: 6)<br><br>## Sample List<br>lst = [10, 20, 30, 40, 50]<br><br>--------------------------------------------------<br><br>## 1. Basic Unpacking<br>Assign each element to a variable.<br><br>Code:<br>a, b, c, d, e = lst<br>print(a, b, c, d, e)<br><br>Output:<br>10 20 30 40 50<br><br>--------------------------------------------------<br><br>## 2. Unpacking with *<br>Assign remaining elements to a list.<br><br>Code:<br>a, *b, c = lst<br>print(a)<br>print(b)<br>print(c)<br><br>Output:<br>10<br>[20, 30, 40]<br>50<br><br>--------------------------------------------------<br><br>## 3. Unpacking into variables ignoring some values<br>Use `_` for values to ignore.<br><br>Code:<br>a, _, c, _, e = lst<br>print(a, c, e)<br><br>Output:<br>10 30 50<br><br>--------------------------------------------------<br><br>## 4. Unpacking Nested Lists<br>Unpack inner lists.<br><br>Code:<br>nested = [[1, 2], [3, 4]]<br>(a, b), (c, d) = nested<br>print(a, b, c, d)<br><br>Output:<br>1 2 3 4<br><br>--------------------------------------------------<br><br>## 5. Swapping Values Using Unpacking<br>Swap two variables without temp.<br><br>Code:<br>x = 10<br>y = 20<br>x, y = y, x<br>print(x, y)<br><br>Output:<br>20 10<br><br>--------------------------------------------------<br><br>## 6. Extended Iterable Unpacking<br>Capture multiple elements in middle.<br><br>Code:<br>lst2 = [1,2,3,4,5,6]<br>a, *b, c, d = lst2<br>print(a)<br>print(b)<br>print(c)<br>print(d)<br><br>Output:<br>1<br>[2, 3, 4]<br>5<br>6<br><br>--------------------------------------------------<br><br># Summary<br>Total List Unpacking Techniques = 6<br>- Basic, with *, ignoring values, nested, swapping, extended<br>- Works with any iterable (lists, tuples, strings)Extended unpacking:</pre><pre>a = [1, 2, 3, 4, 5]<br>x, *y, z = a<br>print(x, y, z)  # 1 [2, 3, 4] 5</pre><h3>17. Membership Testing</h3><p>Checking if an element exists.</p><pre># Python List Membership Testing (Total: 4)<br><br>## Sample List<br>lst = [10, 20, 30, 40, 50]<br><br>--------------------------------------------------<br><br>## 1. Using `in` Operator<br>Check if element exists in list.<br><br>Code:<br>print(20 in lst)<br>print(60 in lst)<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br>## 2. Using `not in` Operator<br>Check if element does NOT exist.<br><br>Code:<br>print(60 not in lst)<br>print(30 not in lst)<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br>## 3. Using `any()` with Condition<br>Check if any element satisfies condition.<br><br>Code:<br>print(any(x &gt; 35 for x in lst))<br>print(any(x &gt; 100 for x in lst))<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br>## 4. Using `all()` with Condition<br>Check if all elements satisfy condition.<br><br>Code:<br>print(all(x &gt; 5 for x in lst))<br>print(all(x &gt; 20 for x in lst))<br><br>Output:<br>True<br>False<br><br>--------------------------------------------------<br><br># Summary<br>Total Membership Testing Techniques = 4<br>- `in` → element exists<br>- `not in` → element does not exist<br>- `any()` → any element satisfies condition<br>- `all()` → all elements satisfy condition</pre><p>(Usually mentioned separately in exams)</p><h3>18. List Sorting Variations</h3><p>Advanced sorting techniques.</p><pre># Python List Sorting Variations (Total: 6)<br><br>## Sample List<br>lst = [40, 10, 50, 20, 30]<br><br>--------------------------------------------------<br><br>## 1. Ascending Sort (Default)<br>Sorts list in increasing order.<br><br>Code:<br>lst.sort()<br>print(lst)<br><br>Output:<br>[10, 20, 30, 40, 50]<br><br>--------------------------------------------------<br><br>## 2. Descending Sort<br>Sorts list in decreasing order.<br><br>Code:<br>lst.sort(reverse=True)<br>print(lst)<br><br>Output:<br>[50, 40, 30, 20, 10]<br><br>--------------------------------------------------<br><br>## 3. Using sorted() (Returns new list)<br>Original list remains unchanged.<br><br>Code:<br>lst = [40, 10, 50, 20, 30]<br>new_lst = sorted(lst)<br>print(&quot;Original:&quot;, lst)<br>print(&quot;Sorted:&quot;, new_lst)<br><br>Output:<br>Original: [40, 10, 50, 20, 30]<br>Sorted: [10, 20, 30, 40, 50]<br><br>--------------------------------------------------<br><br>## 4. sorted() with reverse<br>Sorts new list in descending order.<br><br>Code:<br>new_lst = sorted(lst, reverse=True)<br>print(new_lst)<br><br>Output:<br>[50, 40, 30, 20, 10]<br><br>--------------------------------------------------<br><br>## 5. Sorting with key function (e.g., absolute)<br>Sort based on a function of element.<br><br>Code:<br>lst2 = [-5, 2, -10, 3]<br>lst2.sort(key=abs)<br>print(lst2)<br><br>Output:<br>[2, 3, -5, -10]<br><br>--------------------------------------------------<br><br>## 6. Sorting Strings / Custom key<br>Sort strings ignoring case.<br><br>Code:<br>names = [&quot;Alice&quot;, &quot;bob&quot;, &quot;Charlie&quot;, &quot;dave&quot;]<br>names.sort(key=str.lower)<br>print(names)<br><br>Output:<br>[&#39;Alice&#39;, &#39;bob&#39;, &#39;Charlie&#39;, &#39;dave&#39;]<br><br>--------------------------------------------------<br><br># Summary<br>Total List Sorting Variations = 6<br>- sort() → in-place ascending/descending<br>- sorted() → returns new list<br>- key function → custom sorting</pre><p>Also:</p><ul><li>key= reverse=True</li></ul><h3>19. List Filtering &amp; Mapping</h3><p>Using filter(), map() with lists.</p><pre># Python List Filtering &amp; Mapping (Total: 4)<br><br>## Sample List<br>nums = [1, 2, 3, 4, 5, 6]<br><br>--------------------------------------------------<br><br>## 1. Filtering with list comprehension<br>Select elements based on a condition.<br><br>Code:<br>even_nums = [x for x in nums if x % 2 == 0]<br>print(even_nums)<br><br>Output:<br>[2, 4, 6]<br><br>--------------------------------------------------<br><br>## 2. Mapping with list comprehension<br>Apply operation on each element.<br><br>Code:<br>squared = [x**2 for x in nums]<br>print(squared)<br><br>Output:<br>[1, 4, 9, 16, 25, 36]<br><br>--------------------------------------------------<br><br>## 3. Filtering with filter() function<br>Use filter() with lambda.<br><br>Code:<br>even_nums = list(filter(lambda x: x % 2 == 0, nums))<br>print(even_nums)<br><br>Output:<br>[2, 4, 6]<br><br>--------------------------------------------------<br><br>## 4. Mapping with map() function<br>Use map() with lambda or function.<br><br>Code:<br>squared = list(map(lambda x: x**2, nums))<br>print(squared)<br><br>Output:<br>[1, 4, 9, 16, 25, 36]<br><br>--------------------------------------------------<br><br># Summary<br>Total Filtering &amp; Mapping Techniques = 4<br>- List comprehension → compact<br>- filter() / map() → functional style</pre><h3>20. List Conversion</h3><p>Converting other data types to list.</p><pre># Python List Conversion (Total: 5)<br><br>## Sample Data<br>tup = (1, 2, 3)<br>s = &quot;python&quot;<br>dict_items = {&#39;a&#39;: 1, &#39;b&#39;: 2}<br><br>--------------------------------------------------<br><br>## 1. Tuple to List<br>Convert tuple to list.<br><br>Code:<br>lst = list(tup)<br>print(lst)<br><br>Output:<br>[1, 2, 3]<br><br>--------------------------------------------------<br><br>## 2. String to List<br>Convert string to list of characters.<br><br>Code:<br>lst = list(s)<br>print(lst)<br><br>Output:<br>[&#39;p&#39;, &#39;y&#39;, &#39;t&#39;, &#39;h&#39;, &#39;o&#39;, &#39;n&#39;]<br><br>--------------------------------------------------<br><br>## 3. Set to List<br>Convert set to list.<br><br>Code:<br>st = {10, 20, 30}<br>lst = list(st)<br>print(lst)<br><br>Output:<br>[10, 20, 30]  # order may vary<br><br>--------------------------------------------------<br><br>## 4. Dictionary Keys / Values to List<br>Convert keys or values to list.<br><br>Code:<br>lst_keys = list(dict_items.keys())<br>lst_values = list(dict_items.values())<br>print(lst_keys)<br>print(lst_values)<br><br>Output:<br>[&#39;a&#39;, &#39;b&#39;]<br>[1, 2]<br><br>--------------------------------------------------<br><br>## 5. Range to List<br>Convert range object to list.<br><br>Code:<br>lst = list(range(5))<br>print(lst)<br><br>Output:<br>[0, 1, 2, 3, 4]<br><br>--------------------------------------------------<br><br># Summary<br>Total List Conversion Techniques = 5<br>- tuple → list<br>- string → list<br>- set → list<br>- dict keys/values → list<br>- range → list</pre><h3>21. List Copy vs Deep Copy</h3><p>Understanding shallow vs deep copy.</p><pre># Python List Copy vs Deep Copy (Total: 4)<br><br>## Sample Nested List<br>import copy<br>lst = [[1, 2], [3, 4]]<br><br>--------------------------------------------------<br><br>## 1. Assignment (Reference Copy)<br>Both variables point to the same object.<br><br>Code:<br>a = lst<br>a[0][0] = 10<br>print(lst)<br>print(a)<br><br>Output:<br>[[10, 2], [3, 4]]<br>[[10, 2], [3, 4]]<br><br>--------------------------------------------------<br><br>## 2. Shallow Copy Using list() or [:]<br>Outer list copied, inner lists still referenced.<br><br>Code:<br>a = lst[:]<br>a[0][1] = 20<br>print(lst)<br>print(a)<br><br>Output:<br>[[10, 20], [3, 4]]<br>[[10, 20], [3, 4]]<br><br>--------------------------------------------------<br><br>## 3. Shallow Copy Using copy.copy()<br>Similar to slicing, only outer list copied.<br><br>Code:<br>a = copy.copy(lst)<br>a[1][0] = 30<br>print(lst)<br>print(a)<br><br>Output:<br>[[10, 20], [30, 4]]<br>[[10, 20], [30, 4]]<br><br>--------------------------------------------------<br><br>## 4. Deep Copy Using copy.deepcopy()<br>Copies outer and inner lists completely.<br><br>Code:<br>a = copy.deepcopy(lst)<br>a[1][1] = 40<br>print(lst)<br>print(a)<br><br>Output:<br>[[10, 20], [30, 4]]<br>[[10, 20], [30, 40]]<br><br>--------------------------------------------------<br><br># Summary<br>Total Copy Techniques = 4<br>- Assignment → reference copy (shared object)<br>- Shallow copy → outer copied, inner shared<br>- Deep copy → completely independent copy</pre><h3>22. List Performance &amp; Time Complexity</h3><p>(Important for DSA &amp; interviews)</p><pre># Python List Performance &amp; Time Complexity (Total: 10)<br><br>## Sample List<br>lst = [1, 2, 3, 4, 5]<br><br>--------------------------------------------------<br><br>## 1. Access by Index<br>Time Complexity: O(1)<br><br>Code:<br>print(lst[2])<br><br>Output:<br>3<br><br>--------------------------------------------------<br><br>## 2. Search for Element<br>Time Complexity: O(n)<br><br>Code:<br>print(3 in lst)<br>print(lst.index(4))<br><br>Output:<br>True<br>3<br><br>--------------------------------------------------<br><br>## 3. Append Element<br>Time Complexity: O(1) amortized<br><br>Code:<br>lst.append(6)<br>print(lst)<br><br>Output:<br>[1, 2, 3, 4, 5, 6]<br><br>--------------------------------------------------<br><br>## 4. Insert Element<br>Time Complexity: O(n) (elements shifted)<br><br>Code:<br>lst.insert(2, 99)<br>print(lst)<br><br>Output:<br>[1, 2, 99, 3, 4, 5, 6]<br><br>--------------------------------------------------<br><br>## 5. Delete by Index (pop)<br>Time Complexity: O(n) if pop(0), O(1) if pop() from end<br><br>Code:<br>lst.pop()<br>lst.pop(0)<br>print(lst)<br><br>Output:<br>[2, 99, 3, 4, 5]<br><br>--------------------------------------------------<br><br>## 6. Delete by Value (remove)<br>Time Complexity: O(n)<br><br>Code:<br>lst.remove(99)<br>print(lst)<br><br>Output:<br>[2, 3, 4, 5]<br><br>--------------------------------------------------<br><br>## 7. Copy / Shallow Copy<br>Time Complexity: O(n)<br><br>Code:<br>lst2 = lst[:]<br>print(lst2)<br><br>Output:<br>[2, 3, 4, 5]<br><br>--------------------------------------------------<br><br>## 8. Concatenation (+)<br>Time Complexity: O(n + m)<br><br>Code:<br>lst3 = lst + [6, 7, 8]<br>print(lst3)<br><br>Output:<br>[2, 3, 4, 5, 6, 7, 8]<br><br>--------------------------------------------------<br><br>## 9. Iteration / Traversal<br>Time Complexity: O(n)<br><br>Code:<br>for x in lst:<br>    print(x, end=&quot; &quot;)<br><br>Output:<br>2 3 4 5 <br><br>--------------------------------------------------<br><br>## 10. Sort<br>Time Complexity: O(n log n)<br><br>Code:<br>lst4 = [5, 1, 3, 2, 4]<br>lst4.sort()<br>print(lst4)<br><br>Output:<br>[1, 2, 3, 4, 5]<br><br>--------------------------------------------------<br><br># Summary<br>Python List Time Complexities:<br>- Access → O(1)<br>- Search → O(n)<br>- Append → O(1) amortized<br>- Insert / Delete → O(n)<br>- Copy / Concatenation → O(n)<br>- Iteration → O(n)<br>- Sort → O(n log n)</pre><h3>23. List vs Other Data Structures</h3><p>Comparison category.</p><pre># Python List vs Other Data Structures (Total: 6)<br><br>## Sample Data<br>lst = [1, 2, 3, 4, 5]<br>tup = (1, 2, 3, 4, 5)<br>st = {1, 2, 3, 4, 5}<br>d = {&#39;a&#39;: 1, &#39;b&#39;: 2}<br><br>--------------------------------------------------<br><br>## 1. List vs Tuple<br>- List is mutable, Tuple is immutable<br>- List uses more memory than Tuple<br><br>Code:<br>lst[0] = 10<br>print(lst)<br>print(tup[0])  # tuple immutable<br><br>Output:<br>[10, 2, 3, 4, 5]<br>1<br><br>--------------------------------------------------<br><br>## 2. List vs Set<br>- List preserves order, Set is unordered<br>- List allows duplicates, Set only unique elements<br><br>Code:<br>st.add(6)<br>print(lst)<br>print(st)<br><br>Output:<br>[10, 2, 3, 4, 5]<br>{1, 2, 3, 4, 5, 6}<br><br>--------------------------------------------------<br><br>## 3. List vs Dictionary<br>- List stores elements by index, Dictionary stores key-value pairs<br>- List access by index, Dictionary access by key<br><br>Code:<br>print(lst[0])<br>print(d[&#39;a&#39;])<br><br>Output:<br>10<br>1<br><br>--------------------------------------------------<br><br>## 4. Performance Differences<br>| Operation       | List      | Tuple      | Set      | Dict      |<br>|-----------------|-----------|------------|----------|----------|<br>| Access          | O(1)      | O(1)       | N/A      | O(1)     |<br>| Search          | O(n)      | O(n)       | O(1)     | O(1)     |<br>| Insert/Append   | O(1)      | N/A        | O(1)     | O(1)     |<br>| Delete          | O(n)      | N/A        | O(1)     | O(1)     |<br><br>--------------------------------------------------<br><br>## 5. Use Cases Comparison<br>- List → Ordered collection, allows duplicates, good for sequences  <br>- Tuple → Fixed collection, memory efficient, hashable  <br>- Set → Unique elements, fast membership testing  <br>- Dict → Key-value pairs, fast lookups, flexible storage  <br><br>--------------------------------------------------<br><br>## 6. Conversion Between Structures<br>Code:<br># List → Tuple / Set<br>t = tuple(lst)<br>s = set(lst)<br>print(t)<br>print(s)<br><br># Tuple → List<br>l2 = list(tup)<br>print(l2)<br><br>Output:<br>(10, 2, 3, 4, 5)<br>{10, 2, 3, 4, 5}<br>[1, 2, 3, 4, 5]<br><br>--------------------------------------------------<br><br># Summary<br>Total Key Comparisons = 6<br>- Lists are versatile but mutable<br>- Tuples → immutable &amp; memory efficient<br>- Sets → unique &amp; fast membership<br>- Dictionaries → key-value mapping</pre><h3>24. List with Enumerate</h3><p>Access index + value together.</p><pre># Python List with enumerate() (Total: 3)<br><br>## Sample List<br>lst = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;]<br><br>--------------------------------------------------<br><br>## 1. Basic enumerate()<br>Returns index-value pairs.<br><br>Code:<br>for index, value in enumerate(lst):<br>    print(index, value)<br><br>Output:<br>0 a<br>1 b<br>2 c<br>3 d<br><br>--------------------------------------------------<br><br>## 2. enumerate() with start parameter<br>Change starting index.<br><br>Code:<br>for index, value in enumerate(lst, start=1):<br>    print(index, value)<br><br>Output:<br>1 a<br>2 b<br>3 c<br>4 d<br><br>--------------------------------------------------<br><br>## 3. Using enumerate() in List Comprehension<br>Get index-value pairs in a list.<br><br>Code:<br>indexed_lst = [(i, v) for i, v in enumerate(lst)]<br>print(indexed_lst)<br><br>Output:<br>[(0, &#39;a&#39;), (1, &#39;b&#39;), (2, &#39;c&#39;), (3, &#39;d&#39;)]<br><br>--------------------------------------------------<br><br># Summary<br>Total `enumerate()` Techniques = 3<br>- Basic iteration with index<br>- Custom start index<br>- List comprehension usage</pre><h3>25. List with Zip</h3><p>Combining multiple lists.</p><pre># Python List with zip() (Total: 4)<br><br>## Sample Lists<br>a = [1, 2, 3]<br>b = [&#39;x&#39;, &#39;y&#39;, &#39;z&#39;]<br>c = [10, 20, 30]<br><br>--------------------------------------------------<br><br>## 1. Basic zip()<br>Combine two lists element-wise.<br><br>Code:<br>zipped = list(zip(a, b))<br>print(zipped)<br><br>Output:<br>[(1, &#39;x&#39;), (2, &#39;y&#39;), (3, &#39;z&#39;)]<br><br>--------------------------------------------------<br><br>## 2. Zip with multiple lists<br>Combine more than two lists.<br><br>Code:<br>zipped = list(zip(a, b, c))<br>print(zipped)<br><br>Output:<br>[(1, &#39;x&#39;, 10), (2, &#39;y&#39;, 20), (3, &#39;z&#39;, 30)]<br><br>--------------------------------------------------<br><br>## 3. Unzipping using *<br>Separate zipped list back into individual lists.<br><br>Code:<br>zipped = list(zip(a, b))<br>a1, b1 = zip(*zipped)<br>print(a1)<br>print(b1)<br><br>Output:<br>(1, 2, 3)<br>(&#39;x&#39;, &#39;y&#39;, &#39;z&#39;)<br><br>--------------------------------------------------<br><br>## 4. Handling unequal lengths<br>Zip stops at shortest list.<br><br>Code:<br>a = [1, 2, 3, 4]<br>b = [&#39;p&#39;, &#39;q&#39;]<br>zipped = list(zip(a, b))<br>print(zipped)<br><br>Output:<br>[(1, &#39;p&#39;), (2, &#39;q&#39;)]<br><br>--------------------------------------------------<br><br># Summary<br>Total `zip()` Techniques = 4<br>- Combine lists<br>- Multiple lists<br>- Unzip<br>- Handles unequal lengths</pre><h3>26. List Immutability Illusion (Common Pitfall)</h3><p>When modifying while iterating.</p><pre># Python List Immutability Illusion (Total: 4)<br><br>This illusion happens because:<br>- Lists are **mutable**<br>- Variables store **references**, not values<br>- Rebinding ≠ modifying<br><br>--------------------------------------------------<br><br>## 1. Reassignment vs Modification<br>Reassigning creates a new object, not modifying the original list.<br><br>Code:<br>a = [1, 2, 3]<br>b = a<br>b = b + [4]<br>print(a)<br>print(b)<br><br>Output:<br>[1, 2, 3]<br>[1, 2, 3, 4]<br><br>Explanation:<br>`b + [4]` creates a NEW list → `a` unchanged<br><br>--------------------------------------------------<br><br>## 2. Using += vs +<br>`+=` modifies the original list in-place.<br><br>Code:<br>a = [1, 2, 3]<br>b = a<br>b += [4]<br>print(a)<br>print(b)<br><br>Output:<br>[1, 2, 3, 4]<br>[1, 2, 3, 4]<br><br>Explanation:<br>`+=` mutates the list → both references see the change<br><br>--------------------------------------------------<br><br>## 3. Function Argument Trap<br>Modifying list inside function affects original.<br><br>Code:<br>def add_item(lst):<br>    lst.append(100)<br><br>a = [1, 2, 3]<br>add_item(a)<br>print(a)<br><br>Output:<br>[1, 2, 3, 100]<br><br>Explanation:<br>List is passed by reference (object reference)<br><br>--------------------------------------------------<br><br>## 4. Default Mutable Argument Pitfall<br>Default list is shared across function calls.<br><br>Code:<br>def func(x, lst=[]):<br>    lst.append(x)<br>    return lst<br><br>print(func(1))<br>print(func(2))<br>print(func(3))<br><br>Output:<br>[1]<br>[1, 2]<br>[1, 2, 3]<br><br>Correct Way:<br>def func(x, lst=None):<br>    if lst is None:<br>        lst = []<br>    lst.append(x)<br>    return lst<br><br>--------------------------------------------------<br><br># Summary<br>Total Pitfalls = 4<br><br>Key Takeaways:<br>- Lists are mutable<br>- Variables hold references<br>- `+` creates new list<br>- `+=` modifies existing list<br>- Never use mutable default arguments</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ft6kRBS78pLJX_hiIZ8k_Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4debedc22c13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RegEx (Regular Expression)]]></title>
            <link>https://medium.com/@datawhizz.26/regex-regular-expression-fc9f141fb3ce?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc9f141fb3ce</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[regex]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Sun, 25 Jan 2026 09:16:57 GMT</pubDate>
            <atom:updated>2026-01-25T09:16:57.260Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Python Chapter VIII</strong></p><blockquote><strong>RegEx is used to search, match, and manipulate text using patterns.<br> Python provides the </strong><strong><em>”</em></strong><strong>re” module for working with regular expressions.</strong></blockquote><pre>import re</pre><h3><strong>RegEx Functions</strong></h3><ul><li>The re module offers a set of functions that allows us to search a string for a match</li><li>Main Functions → These are called directly from re module</li></ul><pre>import re<br><br>ans = re.search(&quot;ai&quot;, &quot;I love ai&quot;)<br>print(ans)<br><br>print(re.match(&quot;I&quot;, &quot;I love Python&quot;))<br><br>print(re.findall(r&quot;\d&quot;, &quot;a1b2&quot;))     # \d → digits (0–9)<br><br>print(list(re.finditer(r&quot;\d&quot;, &quot;a1b2&quot;)))  # convert iterator to list<br># print(re.compile(r&quot;\d+&quot;))<br>print(re.sub(r&quot;\s&quot;, &quot;-&quot;, &quot;hi all&quot;))  # \s → whitespace<br><br>print(re.split(r&quot;\s&quot;, &quot;hi all&quot;))<br><br>print(re.fullmatch(r&quot;\d+&quot;, &quot;a1b2&quot;))<br><br>print(re.fullmatch(r&quot;\d+&quot;, &quot;123&quot;))<br><br>print(re.subn(r&quot;\s&quot;, &quot;-&quot;, &quot;a b&quot;))<br><br>print(re.escape(&quot;a.b&quot;))</pre><pre># output<br>&lt;main.py&gt;:27: SyntaxWarning: invalid escape sequence &#39;\d&#39;<br>&lt;re.Match object; span=(7, 9), match=&#39;ai&#39;&gt; # span(start,end)<br>&lt;re.Match object; span=(0, 1), match=&#39;I&#39;&gt;<br>[&#39;1&#39;, &#39;2&#39;]<br>[&lt;re.Match object; span=(1, 2), match=&#39;1&#39;&gt;, &lt;re.Match object; span=(3, 4), match=&#39;2&#39;&gt;]<br>hi-all<br>[&#39;hi&#39;, &#39;all&#39;]<br>None<br>&lt;re.Match object; span=(0, 3), match=&#39;123&#39;&gt;<br>(&#39;a-b&#39;, 1)<br>a\.b</pre><h3>2. Pattern Object Methods</h3><ul><li>(created using re.compile())</li></ul><pre>import re<br>pattern = re.compile(r&quot;\d+&quot;)<br>text = &quot;Age 25 and score 90&quot;<br>print(pattern.search(text))<br>print(pattern.match(text))<br>print(pattern.fullmatch(&quot;25&quot;))<br>print(pattern.findall(text))<br>for m in pattern.finditer(text):<br>    print(m.group())<br>print(pattern.sub(&quot;#&quot;, text))<br>print(pattern.subn(&quot;#&quot;, text))<br>print(pattern.split(text))</pre><pre>&lt;re.Match object; span=(4, 6), match=&#39;25&#39;&gt;<br>None<br>&lt;re.Match object; span=(0, 2), match=&#39;25&#39;&gt;<br>[&#39;25&#39;, &#39;90&#39;]<br>25<br>90<br>Age # and score #<br>(&#39;Age # and score #&#39;, 2)<br>[&#39;Age &#39;, &#39; and score &#39;, &#39;&#39;]</pre><h3>3. Match Object Methods</h3><p>(returned by search, match, fullmatch)</p><pre>import re<br><br>text = &quot;Age: 25&quot;<br>pattern = re.compile(r&quot;Age:\s(?P&lt;age&gt;\d+)&quot;)<br>match = pattern.search(text)<br><br>print(match.group())<br>print(match.group(1))<br>print(match.groups())<br>print(match.groupdict())<br>print(match.start())<br>print(match.end())<br>print(match.span())<br>print(match.re)<br>print(match.string)</pre><pre>#output<br>Age: 25<br>25<br>(&#39;25&#39;,)<br>{&#39;age&#39;: &#39;25&#39;}<br>0<br>7<br>(0, 7)<br>re.compile(&#39;Age:\\s(?P&lt;age&gt;\\d+)&#39;)<br>Age: 25</pre><h3>4. RegEx Utilities &amp; Types</h3><pre>import re<br>re.purge()<br>print(&quot;Cache cleared&quot;)<br>try:<br>    re.compile(&quot;[a-&quot;)<br>except re.error as e:<br>    print(&quot;Invalid regex&quot;)<br>    <br>p = re.compile(r&quot;\d+&quot;)<br>print(type(p) == re.Pattern)<br>m = re.search(r&quot;\d+&quot;, &quot;Age 25&quot;)<br>print(type(m) == re.Match)</pre><pre>#output<br>Cache cleared<br>Invalid regex<br>True<br>True</pre><p>Below is a <strong>clear, corrected, and well-structured Markdown explanation</strong> of the <strong>Match Object in Python Regular Expressions</strong>, with <strong>examples and outputs</strong> for easy understanding.</p><h3>Match Object in Regular Expressions</h3><p>A <strong>Match Object</strong> is returned when a regular expression <strong>successfully finds a match</strong> in a string using functions like re.search(), re.match(), etc.</p><p>📌 <strong>Important Note</strong></p><ul><li>If a match is found → a <strong>Match Object</strong> is returned</li><li>If no match is found → <strong>None</strong> is returned</li></ul><h3>Creating a Match Object</h3><pre>import re<br>txt = &quot;The rain in Spain&quot;<br>x = re.search(&quot;ai&quot;, txt)<br>print(x)</pre><h3>Output</h3><pre>&lt;re.Match object; span=(5, 7), match=&#39;ai&#39;&gt;</pre><p>This confirms that a <strong>Match Object</strong> is created.</p><h3>Properties &amp; Methods of Match Object</h3><p>Method / PropertyDescriptionspan()Returns start and end position of the matchstringReturns the original stringgroup()Returns the matched substring</p><h3>.span()</h3><p><strong>Returns a tuple → (start_index, end_index)</strong></p><h3>Pattern:</h3><p>Find words that start with <strong>capital “S”</strong></p><pre>import re<br>txt = &quot;The rain in Spain&quot;<br>x = re.search(r&quot;\bS\w+&quot;, txt)<br>print(x.span())</pre><h3>Output</h3><pre>(12, 17)</pre><p>Match found from index <strong>12 to 17</strong> (Spain)</p><h3>.string</h3><p><strong>Returns the original string passed to the function</strong></p><pre>import re<br>txt = &quot;The rain in Spain&quot;<br>x = re.search(r&quot;\bS\w+&quot;, txt)<br>print(x.string)</pre><h3>Output</h3><pre>The rain in Spain</pre><h3>.group()</h3><p><strong>Returns the actual matched text</strong></p><pre>import re<br>txt = &quot;The rain in Spain&quot;<br>x = re.search(r&quot;\bS\w+&quot;, txt)<br>print(x.group())</pre><h3>Output</h3><pre>Spain</pre><h3>When No Match Is Found</h3><pre>import re<br>txt = &quot;The rain in Spain&quot;<br>x = re.search(&quot;USA&quot;, txt)<br>print(x)</pre><h3>Output</h3><pre>None</pre><p>.span() → position</p><p>.string → original string</p><p>.group() → matched text</p><h3>Meta Characters in Regular Expressions</h3><blockquote>In <strong>Regular Expressions (RegEx)</strong>, <strong>meta characters</strong> are special symbols with predefined meanings. They help us build powerful patterns for matching strings.</blockquote><p>We use Python’s built-in <strong>re module`</strong> to work with regular expressions.</p><pre>import re</pre><h3>1. Dot (.)</h3><p><strong>Meaning:</strong><br>Matches <strong>any single character except newline (</strong><strong>\n)</strong></p><p><strong>Pattern:</strong> c.t</p><pre>s1 = &quot;cat&quot;<br>s2 = &quot;cut&quot;<br>s3 = &quot;cot&quot;<br>s4 = &quot;pot&quot;<br>print(re.search(&#39;c.t&#39;, s1))<br>print(re.search(&#39;c.t&#39;, s2))<br>print(re.search(&#39;c.t&#39;, s3))<br>print(re.search(&#39;c.t&#39;, s4))</pre><h3>Output</h3><pre>&lt;re.Match object; span=(0, 3), match=&#39;cat&#39;&gt;<br>&lt;re.Match object; span=(0, 3), match=&#39;cut&#39;&gt;<br>&lt;re.Match object; span=(0, 3), match=&#39;cot&#39;&gt;<br>None</pre><h3>2. Caret (^)</h3><p><strong>Meaning:</strong><br>Matches the <strong>start of a string</strong></p><p><strong>Pattern:</strong> ^m</p><pre>s1 = &#39;mumbai&#39;<br>s2 = &#39;kolkata&#39;<br>s3 = &#39;chennai&#39;<br>s4 = &#39;delhi&#39;<br>print(re.search(&#39;^m&#39;, s1))<br>print(re.search(&#39;^m&#39;, s2))<br>print(re.search(&#39;^m&#39;, s3))<br>print(re.search(&#39;^m&#39;, s4))</pre><h3>Output</h3><pre>&lt;re.Match object; span=(0, 1), match=&#39;m&#39;&gt;<br>None<br>None<br>None</pre><h3>3. Dollar ($)</h3><p><strong>Meaning:</strong><br>Matches the <strong>end of a string</strong></p><p><strong>Pattern:</strong> a$</p><pre>print(re.search(&#39;a$&#39;, s1))<br>print(re.search(&#39;a$&#39;, s2))<br>print(re.search(&#39;a$&#39;, s3))<br>print(re.search(&#39;a$&#39;, s4))</pre><h3>Output</h3><pre>None<br>&lt;re.Match object; span=(7, 8), match=&#39;a&#39;&gt;<br>None<br>None</pre><h3>4. Asterisk (*)</h3><p><strong>Meaning:</strong><br>Matches <strong>zero or more occurrences</strong> of the preceding character</p><p><strong>Pattern:</strong> ab*c</p><pre>s1 = &quot;ac&quot;<br>s2 = &quot;abc&quot;<br>s3 = &quot;abbc&quot;<br>s4 = &quot;cab&quot;<br>print(re.search(&#39;ab*c&#39;, s1))<br>print(re.search(&#39;ab*c&#39;, s2))<br>print(re.search(&#39;ab*c&#39;, s3))<br>print(re.search(&#39;ab*c&#39;, s4))</pre><h3>Output</h3><pre>&lt;re.Match object; match=&#39;ac&#39;&gt;<br>&lt;re.Match object; match=&#39;abc&#39;&gt;<br>&lt;re.Match object; match=&#39;abbc&#39;&gt;<br>None</pre><h3>5. Plus (+)</h3><p><strong>Meaning:</strong><br>Matches <strong>one or more occurrences</strong> of the preceding character</p><p><strong>Pattern:</strong> ab+c</p><pre>print(re.search(&#39;ab+c&#39;, s1))<br>print(re.search(&#39;ab+c&#39;, s2))<br>print(re.search(&#39;ab+c&#39;, s3))<br>print(re.search(&#39;ab+c&#39;, s4))</pre><h3>Output</h3><pre>None<br>&lt;re.Match object; match=&#39;abc&#39;&gt;<br>&lt;re.Match object; match=&#39;abbc&#39;&gt;<br>None</pre><h3>6. Question Mark (?)</h3><p><strong>Meaning:</strong><br>Matches <strong>zero or one occurrence</strong> of the preceding character</p><p><strong>Pattern:</strong> colou?r</p><pre>s1 = &quot;color&quot;<br>s2 = &quot;colour&quot;<br>s3 = &quot;colouur&quot;<br>print(re.search(&#39;colou?r&#39;, s1))<br>print(re.search(&#39;colou?r&#39;, s2))<br>print(re.search(&#39;colou?r&#39;, s3))</pre><h3>Output</h3><pre>&lt;re.Match object; match=&#39;color&#39;&gt;<br>&lt;re.Match object; match=&#39;colour&#39;&gt;<br>None</pre><h3>7. Square Brackets ([])</h3><p><strong>Meaning:</strong><br>Matches <strong>any one character</strong> inside the brackets</p><p><strong>Pattern:</strong> [in] → matches i OR n</p><pre>s1 = &quot;My Name is Akash Khanna, I Live in Mumbai.&quot;<br>s2 = &quot;I am a Housewife&quot;<br>s3 = &quot;He never loves to cook&quot;<br>print(re.search(&#39;[in]&#39;, s1))<br>print(re.search(&#39;[in]&#39;, s2))<br>print(re.search(&#39;[in]&#39;, s3))</pre><h3>Output</h3><pre>&lt;re.Match object; match=&#39;N&#39;&gt;<br>&lt;re.Match object; match=&#39;i&#39;&gt;<br>&lt;re.Match object; match=&#39;n&#39;&gt;</pre><h3>8. Negated Set ([^ ])</h3><p><strong>Meaning:</strong><br>Matches <strong>any character NOT inside the brackets</strong></p><p><strong>Pattern:</strong> [^0-9] → any <strong>non-digit</strong></p><pre>s1 = &quot;I am an actor&quot;<br>s2 = &quot;I earn 25 Lakhs per annum&quot;<br>s3 = &quot;I stay in Mumbai&quot;<br>s4 = &quot;4590&quot;<br>print(re.search(&#39;[^0-9]&#39;, s1))<br>print(re.search(&#39;[^0-9]&#39;, s2))<br>print(re.search(&#39;[^0-9]&#39;, s3))<br>print(re.search(&#39;[^0-9]&#39;, s4))</pre><h3>Output</h3><pre>&lt;re.Match object; match=&#39;I&#39;&gt;<br>&lt;re.Match object; match=&#39;I&#39;&gt;<br>&lt;re.Match object; match=&#39;I&#39;&gt;<br>None</pre><h3>9. Pipe (|)</h3><p><strong>Meaning:</strong><br>Acts as <strong>OR operator</strong></p><p><strong>Pattern:</strong> mango|papaya</p><pre>s1 = &quot;I love to eat mango&quot;<br>s2 = &quot;I love to eat banana&quot;<br>s3 = &quot;I love to eat orange&quot;<br>s4 = &quot;I love to eat papaya&quot;<br>print(re.search(&#39;mango|papaya&#39;, s1))<br>print(re.search(&#39;mango|papaya&#39;, s2))<br>print(re.search(&#39;mango|papaya&#39;, s3))<br>print(re.search(&#39;mango|papaya&#39;, s4))</pre><h3>Output</h3><pre>&lt;re.Match object; match=&#39;mango&#39;&gt;<br>None<br>None<br>&lt;re.Match object; match=&#39;papaya&#39;&gt;</pre><pre>import re<br><br>print(&quot;1. Dot (.) – Any character except newline&quot;)<br>print(re.findall(r&quot;a.b&quot;, &quot;acb a1b a\nb&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;2. Caret (^) – Start of string&quot;)<br>print(re.findall(r&quot;^Hello&quot;, &quot;Hello World&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;3. Dollar ($) – End of string&quot;)<br>print(re.findall(r&quot;end$&quot;, &quot;the end&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;4. Star (*) – 0 or more&quot;)<br>print(re.findall(r&quot;ab*&quot;, &quot;a ab abb&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;5. Plus (+) – 1 or more&quot;)<br>print(re.findall(r&quot;ab+&quot;, &quot;a ab abb&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;6. Question (?) – 0 or 1&quot;)<br>print(re.findall(r&quot;ab?&quot;, &quot;a ab abb&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;7. {n} – Exactly n times&quot;)<br>print(re.findall(r&quot;\d{3}&quot;, &quot;123 45 6789&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;8. {n,} – At least n times&quot;)<br>print(re.findall(r&quot;\d{2,}&quot;, &quot;1 22 333&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;9. {n,m} – Between n and m times&quot;)<br>print(re.findall(r&quot;\d{2,3}&quot;, &quot;1 22 333 4444&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;10. [ ] – Character set&quot;)<br>print(re.findall(r&quot;[aeiou]&quot;, &quot;hello&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;11. [^ ] – Negated set&quot;)<br>print(re.findall(r&quot;[^aeiou]&quot;, &quot;hi&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;12. ( ) – Capturing group&quot;)<br>m = re.search(r&quot;Age (\d+)&quot;, &quot;Age 25&quot;)<br>print(m.group(1))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;13. | – OR operator&quot;)<br>print(re.findall(r&quot;cat|dog&quot;, &quot;cat dog cow&quot;))<br>print(&quot;-&quot; * 40)<br><br>print(&quot;14. \\ – Escape character&quot;)<br>print(re.findall(r&quot;\.&quot;, &quot;a.b.c&quot;))<br>print(&quot;-&quot; * 40)<br><br>#output<br>1. Dot (.) – Any character except newline<br>[&#39;acb&#39;, &#39;a1b&#39;]<br>----------------------------------------<br>2. Caret (^) – Start of string<br>[&#39;Hello&#39;]<br>----------------------------------------<br>3. Dollar ($) – End of string<br>[&#39;end&#39;]<br>----------------------------------------<br>4. Star (*) – 0 or more<br>[&#39;a&#39;, &#39;ab&#39;, &#39;abb&#39;]<br>----------------------------------------<br>5. Plus (+) – 1 or more<br>[&#39;ab&#39;, &#39;abb&#39;]<br>----------------------------------------<br>6. Question (?) – 0 or 1<br>[&#39;a&#39;, &#39;ab&#39;, &#39;ab&#39;]<br>----------------------------------------<br>7. {n} – Exactly n times<br>[&#39;123&#39;, &#39;678&#39;]<br>----------------------------------------<br>8. {n,} – At least n times<br>[&#39;22&#39;, &#39;333&#39;]<br>----------------------------------------<br>9. {n,m} – Between n and m times<br>[&#39;22&#39;, &#39;333&#39;, &#39;444&#39;]<br>----------------------------------------<br>10. [ ] – Character set<br>[&#39;e&#39;, &#39;o&#39;]<br>----------------------------------------<br>11. [^ ] – Negated set<br>[&#39;h&#39;]<br>----------------------------------------<br>12. ( ) – Capturing group<br>25<br>----------------------------------------<br>13. | – OR operator<br>[&#39;cat&#39;, &#39;dog&#39;]<br>----------------------------------------<br>14. \ – Escape character<br>[&#39;.&#39;, &#39;.&#39;]<br>----------------------------------------</pre><h3>2. Grouping &amp; Lookaround Metacharacters</h3><pre>import re<br><br>print(&quot;15. (?:...) – Non-capturing group&quot;)<br>print(re.findall(r&quot;(?:ab)+&quot;, &quot;ab abab abc&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;16. (?P&lt;name&gt;...) – Named capturing group&quot;)<br>m = re.search(r&quot;(?P&lt;num&gt;\d+)&quot;, &quot;Age 25&quot;)<br>print(m.groupdict())<br>print(&quot;-&quot; * 50)<br><br>print(&quot;17. (?=...) – Positive lookahead&quot;)<br>print(re.findall(r&quot;\w+(?=\d)&quot;, &quot;item1 item2 box&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;18. (?!...) – Negative lookahead&quot;)<br>print(re.findall(r&quot;cat(?!s)&quot;, &quot;cat cats cat&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;19. (?&lt;=...) – Positive lookbehind&quot;)<br>print(re.findall(r&quot;(?&lt;=₹)\d+&quot;, &quot;₹500 ₹600&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;20. (?&lt;!...) – Negative lookbehind&quot;)<br>print(re.findall(r&quot;(?&lt;!₹)\d+&quot;, &quot;500 ₹600&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;21. () – Group reference (capturing group)&quot;)<br>m = re.search(r&quot;(hello)&quot;, &quot;say hello&quot;)<br>print(m.group(1))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;22. \\1, \\2 – Backreference&quot;)<br>print(re.findall(r&quot;(\b\w+)\s+\1&quot;, &quot;hello hello hi hi&quot;))<br>print(&quot;-&quot; * 50)<br><br>#output<br>15. (?:...) – Non-capturing group<br>[&#39;ab&#39;, &#39;abab&#39;]<br>--------------------------------------------------<br>16. (?P&lt;name&gt;...) – Named capturing group<br>{&#39;num&#39;: &#39;25&#39;}<br>--------------------------------------------------<br>17. (?=...) – Positive lookahead<br>[&#39;item&#39;, &#39;item&#39;]<br>--------------------------------------------------<br>18. (?!...) – Negative lookahead<br>[&#39;cat&#39;, &#39;cat&#39;]<br>--------------------------------------------------<br>19. (?&lt;=...) – Positive lookbehind<br>[&#39;500&#39;, &#39;600&#39;]<br>--------------------------------------------------<br>20. (?&lt;!...) – Negative lookbehind<br>[&#39;500&#39;]<br>--------------------------------------------------<br>21. () – Group reference (capturing group)<br>hello<br>--------------------------------------------------<br>22. \1, \2 – Backreference<br>[&#39;hello&#39;, &#39;hi&#39;]<br>--------------------------------------------------</pre><h3>3. Inline Flags &amp; Special Constructs</h3><pre>import re<br><br>print(&quot;23. (?i) – Ignore case&quot;)<br>print(re.findall(r&quot;(?i)python&quot;, &quot;Python PYTHON PyThOn&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;24. (?m) – Multiline&quot;)<br>text = &quot;Hello\nWorld&quot;<br>print(re.findall(r&quot;(?m)^World&quot;, text))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;25. (?s) – Dot matches newline&quot;)<br>print(re.findall(r&quot;(?s)a.*b&quot;, &quot;a\nb&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;26. (?x) – Verbose mode&quot;)<br>pattern = r&quot;&quot;&quot;<br>(?x)            # Verbose mode<br>\d{3}           # Area code<br>-               # Dash<br>\d{3}           # First part<br>-               # Dash<br>\d{4}           # Last part<br>&quot;&quot;&quot;<br>print(re.findall(pattern, &quot;123-456-7890&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;27. (?&gt;...) – Atomic group (rare)&quot;)<br># Python supports atomic grouping in recent versions<br>print(re.findall(r&quot;(?&gt;ab)+&quot;, &quot;ab abab ab&quot;))<br>print(&quot;-&quot; * 50)<br><br>#output<br>23. (?i) – Ignore case<br>[&#39;Python&#39;, &#39;PYTHON&#39;, &#39;PyThOn&#39;]<br>--------------------------------------------------<br>24. (?m) – Multiline<br>[&#39;World&#39;]<br>--------------------------------------------------<br>25. (?s) – Dot matches newline<br>[&#39;a\nb&#39;]<br>--------------------------------------------------<br>26. (?x) – Verbose mode<br>[&#39;123-456-7890&#39;]<br>--------------------------------------------------<br>27. (?&gt;...) – Atomic group (rare)<br>[&#39;ab&#39;, &#39;abab&#39;, &#39;ab&#39;]<br>--------------------------------------------------</pre><h3><strong>RegEx Flag</strong></h3><ul><li><strong>Flags</strong> modify how a RegEx pattern behaves.</li></ul><p>They can be used in <strong>two ways</strong>:</p><ul><li>As an argument → re.search(pattern, text, flag)</li><li>Inline → (?i), (?m) etc.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/425a9c708b3bb6fbbe7053d1d40e45a0/href">https://medium.com/media/425a9c708b3bb6fbbe7053d1d40e45a0/href</a></iframe><pre>import re<br><br>print(&quot;1. re.I / IGNORECASE&quot;)<br>print(re.findall(&quot;python&quot;, &quot;Python PYTHON&quot;, re.I))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;2. re.M / MULTILINE&quot;)<br>text = &quot;Hello\nWorld&quot;<br>print(re.findall(&quot;^World&quot;, text, re.M))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;3. re.S / DOTALL&quot;)<br>print(re.findall(&quot;a.*b&quot;, &quot;a\nb&quot;, re.S))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;4. re.X / VERBOSE&quot;)<br>pattern = r&quot;&quot;&quot;<br>\d{3}    # area<br>-        # dash<br>\d{3}<br>-        # dash<br>\d{4}<br>&quot;&quot;&quot;<br>print(re.findall(pattern, &quot;123-456-7890&quot;, re.X))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;5. re.A / ASCII&quot;)<br>print(re.findall(r&quot;\w+&quot;, &quot;café&quot;, re.A))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;6. re.L / LOCALE (system dependent)&quot;)<br>print(re.findall(r&quot;\w+&quot;, &quot;word&quot;, re.L))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;7. re.DEBUG&quot;)<br>re.compile(r&quot;\d+&quot;, re.DEBUG)<br>print(&quot;-&quot; * 50)<br><br>print(&quot;8. re.U / UNICODE (legacy, default in Python 3)&quot;)<br>print(re.findall(r&quot;\w+&quot;, &quot;café&quot;, re.U))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;9. re.TEMPLATE (deprecated)&quot;)<br>try:<br>    re.compile(&quot;abc&quot;, re.TEMPLATE)<br>    print(&quot;TEMPLATE flag used (deprecated)&quot;)<br>except Exception as e:<br>    print(&quot;Error:&quot;, e)<br>print(&quot;-&quot; * 50)</pre><pre>#output<br><br>1. re.I / IGNORECASE<br>[&#39;Python&#39;, &#39;PYTHON&#39;]<br>--------------------------------------------------<br>2. re.M / MULTILINE<br>[&#39;World&#39;]<br>--------------------------------------------------<br>3. re.S / DOTALL<br>[&#39;a\nb&#39;]<br>--------------------------------------------------<br>4. re.X / VERBOSE<br>[&#39;123-456-7890&#39;]<br>--------------------------------------------------<br>5. re.A / ASCII<br>[&#39;caf&#39;]<br>--------------------------------------------------<br>6. re.L / LOCALE (system dependent)<br>[&#39;word&#39;]<br>--------------------------------------------------<br>7. re.DEBUG<br>(MAXIMUM_REPEAT, etc… debug info)<br>--------------------------------------------------<br>8. re.U / UNICODE (legacy, default in Python 3)<br>[&#39;café&#39;]<br>--------------------------------------------------<br>9. re.TEMPLATE (deprecated)<br>TEMPLATE flag used (deprecated)<br>--------------------------------------------------</pre><h3>RegEx special sequence</h3><p>A special sequence is a \ followed by one of the characters</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/722b615cad679645f786b3757a9aa492/href">https://medium.com/media/722b615cad679645f786b3757a9aa492/href</a></iframe><pre>import re<br><br>text = &quot;Hello 123\tWorld\nPython_3&quot;<br><br>print(&quot;1. \\d – Digit&quot;)<br>print(re.findall(r&quot;\d&quot;, text))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;2. \\D – Non-digit&quot;)<br>print(re.findall(r&quot;\D&quot;, &quot;123ABC&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;3. \\w – Word character&quot;)<br>print(re.findall(r&quot;\w&quot;, &quot;Hi_123&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;4. \\W – Non-word character&quot;)<br>print(re.findall(r&quot;\W&quot;, &quot;Hi_123!&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;5. \\s – Whitespace&quot;)<br>print(re.findall(r&quot;\s&quot;, &quot;Hi there&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;6. \\S – Non-whitespace&quot;)<br>print(re.findall(r&quot;\S&quot;, &quot;Hi there&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;7. \\b – Word boundary&quot;)<br>print(re.findall(r&quot;\bcat\b&quot;, &quot;cat scatter cat&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;8. \\B – Not a word boundary&quot;)<br>print(re.findall(r&quot;\Bcat\B&quot;, &quot;scatter&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;9. \\A – Start of string&quot;)<br>print(re.findall(r&quot;\AHello&quot;, &quot;Hello World&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;10. \\Z – End of string&quot;)<br>print(re.findall(r&quot;World\Z&quot;, &quot;Hello World&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;11. \\G – End of previous match&quot;)<br>print([m.group() for m in re.finditer(r&quot;\G\w&quot;, &quot;ABC&quot;)])<br>print(&quot;-&quot; * 50)<br><br>print(&quot;12. \\n – Newline&quot;)<br>print(re.findall(r&quot;\n&quot;, &quot;Hello\nWorld&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;13. \\t – Tab&quot;)<br>print(re.findall(r&quot;\t&quot;, &quot;Hi\tWorld&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;14. \\r – Carriage return&quot;)<br>print(re.findall(r&quot;\r&quot;, &quot;Hello\rWorld&quot;))<br>print(&quot;-&quot; * 50)</pre><pre>#output<br>1. \d – Digit<br>[&#39;1&#39;, &#39;2&#39;, &#39;3&#39;]<br>--------------------------------------------------<br>2. \D – Non-digit<br>[&#39;A&#39;, &#39;B&#39;, &#39;C&#39;]<br>--------------------------------------------------<br>3. \w – Word character<br>[&#39;H&#39;, &#39;i&#39;, &#39;_&#39;, &#39;1&#39;, &#39;2&#39;, &#39;3&#39;]<br>--------------------------------------------------<br>4. \W – Non-word character<br>[&#39;!&#39;]<br>--------------------------------------------------<br>5. \s – Whitespace<br>[&#39; &#39;]<br>--------------------------------------------------<br>6. \S – Non-whitespace<br>[&#39;H&#39;, &#39;i&#39;, &#39;t&#39;, &#39;h&#39;, &#39;e&#39;, &#39;r&#39;, &#39;e&#39;]<br>--------------------------------------------------<br>7. \b – Word boundary<br>[&#39;cat&#39;, &#39;cat&#39;]<br>--------------------------------------------------<br>8. \B – Not a word boundary<br>[&#39;cat&#39;]<br>--------------------------------------------------<br>9. \A – Start of string<br>[&#39;Hello&#39;]<br>--------------------------------------------------<br>10. \Z – End of string<br>[&#39;World&#39;]<br>--------------------------------------------------<br>11. \G – End of previous match<br>[&#39;A&#39;]<br>--------------------------------------------------<br>12. \n – Newline<br>[&#39;\n&#39;]<br>--------------------------------------------------<br>13. \t – Tab<br>[&#39;\t&#39;]<br>--------------------------------------------------<br>14. \r – Carriage return<br>[&#39;\r&#39;]<br>--------------------------------------------------</pre><h3>RegEx Sets</h3><ul><li>A set is a set of characters inside a pair of square brackets [] with a special meaning</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a160faca4bfa204e282c2337650d21a/href">https://medium.com/media/2a160faca4bfa204e282c2337650d21a/href</a></iframe><pre>import re<br><br>print(&quot;1. [abc]&quot;)<br>print(re.findall(r&quot;[abc]&quot;, &quot;apple banana cherry&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;2. [^abc]&quot;)<br>print(re.findall(r&quot;[^abc]&quot;, &quot;abcXYZ&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;3. [a-z]&quot;)<br>print(re.findall(r&quot;[a-z]&quot;, &quot;HelloWorld&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;4. [A-Z]&quot;)<br>print(re.findall(r&quot;[A-Z]&quot;, &quot;HelloWorld&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;5. [0-9]&quot;)<br>print(re.findall(r&quot;[0-9]&quot;, &quot;Room 404&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;6. [a-zA-Z]&quot;)<br>print(re.findall(r&quot;[a-zA-Z]&quot;, &quot;Hi123!&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;7. [a-zA-Z0-9]&quot;)<br>print(re.findall(r&quot;[a-zA-Z0-9]&quot;, &quot;User_007&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;8. [-_.]&quot;)<br>print(re.findall(r&quot;[-_.]&quot;, &quot;file_name-1.0&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;9. [0-5][0-9] (00–59)&quot;)<br>print(re.findall(r&quot;[0-5][0-9]&quot;, &quot;Time 09:45 67&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;10. [+] literal plus&quot;)<br>print(re.findall(r&quot;[+]&quot;, &quot;a+b+c&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;11. [0123]&quot;)<br>print(re.findall(r&quot;[0123]&quot;, &quot;0123456789&quot;))<br>print(&quot;-&quot; * 50)<br><br>print(&quot;12. [a-zA-Z] (case insensitive letters)&quot;)<br>print(re.findall(r&quot;[a-zA-Z]&quot;, &quot;PyTHon3&quot;))<br>print(&quot;-&quot; * 50)</pre><pre>1. [abc]<br>[&#39;a&#39;, &#39;a&#39;, &#39;a&#39;, &#39;c&#39;]<br>--------------------------------------------------<br>2. [^abc]<br>[&#39;X&#39;, &#39;Y&#39;, &#39;Z&#39;]<br>--------------------------------------------------<br>3. [a-z]<br>[&#39;e&#39;, &#39;l&#39;, &#39;l&#39;, &#39;o&#39;, &#39;o&#39;, &#39;r&#39;, &#39;l&#39;, &#39;d&#39;]<br>--------------------------------------------------<br>4. [A-Z]<br>[&#39;H&#39;, &#39;W&#39;]<br>--------------------------------------------------<br>5. [0-9]<br>[&#39;4&#39;, &#39;0&#39;, &#39;4&#39;]<br>--------------------------------------------------<br>6. [a-zA-Z]<br>[&#39;H&#39;, &#39;i&#39;]<br>--------------------------------------------------<br>7. [a-zA-Z0-9]<br>[&#39;U&#39;, &#39;s&#39;, &#39;e&#39;, &#39;r&#39;, &#39;0&#39;, &#39;0&#39;, &#39;7&#39;]<br>--------------------------------------------------<br>8. [-_.]<br>[&#39;_&#39;, &#39;-&#39;, &#39;.&#39;]<br>--------------------------------------------------<br>9. [0-5][0-9]<br>[&#39;09&#39;, &#39;45&#39;]<br>--------------------------------------------------<br>10. [+]<br>[&#39;+&#39;, &#39;+&#39;]<br>--------------------------------------------------<br>11. [0123]<br>[&#39;0&#39;, &#39;1&#39;, &#39;2&#39;, &#39;3&#39;]<br>--------------------------------------------------<br>12. [a-zA-Z]<br>[&#39;P&#39;, &#39;y&#39;, &#39;T&#39;, &#39;H&#39;, &#39;o&#39;, &#39;n&#39;]<br>--------------------------------------------------</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01e473d52dfa0c00086fa9287066234f/href">https://medium.com/media/01e473d52dfa0c00086fa9287066234f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a82b2d0ea31f9ab178e5ba1c32deae2e/href">https://medium.com/media/a82b2d0ea31f9ab178e5ba1c32deae2e/href</a></iframe><blockquote><strong>Flags</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/425a9c708b3bb6fbbe7053d1d40e45a0/href">https://medium.com/media/425a9c708b3bb6fbbe7053d1d40e45a0/href</a></iframe><blockquote><strong>Special Sequences</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/722b615cad679645f786b3757a9aa492/href">https://medium.com/media/722b615cad679645f786b3757a9aa492/href</a></iframe><blockquote><strong>RegEx Set</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a160faca4bfa204e282c2337650d21a/href">https://medium.com/media/2a160faca4bfa204e282c2337650d21a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VbT9fUrKZSIpSGeE6pdkqw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc9f141fb3ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[String]]></title>
            <link>https://medium.com/@datawhizz.26/string-68fa7c250794?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/68fa7c250794</guid>
            <category><![CDATA[string]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[string-formatting]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Sun, 25 Jan 2026 08:52:34 GMT</pubDate>
            <atom:updated>2026-01-25T08:52:34.054Z</atom:updated>
            <content:encoded><![CDATA[<p>Python Chapter VII</p><blockquote>Essential For String Manipulation</blockquote><pre>print(&quot;--String--&quot;)<br># Note: All string methods return new values. They do not change the original string.<br><br>text=&quot;a&quot; # or &#39;a&#39;<br><br>para=&quot;&quot;&quot;<br>The <br>String<br>is <br>my <br>fav<br>&quot;&quot;&quot;<br>#or<br><br>&quot;&quot;&quot;<br>para=&#39;&#39;&#39;<br>The <br>String<br>is <br>my <br>fav<br>&#39;&#39;&#39;<br>&quot;&quot;&quot;<br><br># concentation<br>str=&quot;Hello&quot;<br>print(str + &quot; &quot;+&quot;World!&quot;)<br>#access character in String <br>print(str[0]) #index start with 0<br>#Slicing<br>print(str[0:3])#start,stop,step<br>#negative <br>print(str[-1])#return last character<br><br># Loop through in string <br>for i in str:<br>    print(i)<br><br>#check the character in string<br>print(&#39;p&#39; in str)<br><br>#check the character not in string<br>print(&#39;h&#39; not in str)<br><br>#length in string<br>print(len(str))<br><br>print(chr(97))<br><br>print(ord(&#39;a&#39;))# return ascii number<br><br># print(ascii(&#39;o&#39;))</pre><pre>#output<br>--String--<br>Hello World!<br>H<br>Hel<br>o<br>H<br>e<br>l<br>l<br>o<br>False<br>True<br>5<br>a<br>97</pre><blockquote><strong>Essential String Methods</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61d0545ab2331296cc7494ce01a17956/href">https://medium.com/media/61d0545ab2331296cc7494ce01a17956/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e1e7582b830297a137b9251fd2d50bf/href">https://medium.com/media/6e1e7582b830297a137b9251fd2d50bf/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MoEqmAAR9Sv7X2u3RKwKNw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68fa7c250794" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Date Time]]></title>
            <link>https://medium.com/@datawhizz.26/date-time-0559bd5d3ff7?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/0559bd5d3ff7</guid>
            <category><![CDATA[function]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[datetime]]></category>
            <category><![CDATA[date]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Mon, 15 Dec 2025 07:55:08 GMT</pubDate>
            <atom:updated>2025-12-15T07:55:08.562Z</atom:updated>
            <content:encoded><![CDATA[<p>Python Chapter VI</p><blockquote><strong>Essential datetime module</strong></blockquote><pre>import datetime as dt #or from datetime import date - it allow you don&#39;t use dt.date instead only use date <br>#create a date object<br>mydate=dt.date(year=2001,month=8,day=8)<br>print(f&quot;Date is: {mydate}&quot;)<br># get the current d<br>ate<br>print(dt.date.today())<br># get the curren month<br>print(dt.date.today().month)<br># Get the current year<br>print(dt.date.today().year)<br># Get the current day<br>print(dt.date.today().day)<br>print(dt.datetime.now())<br><br>from datetime import time,timedelta,datetime<br># Create a time object with the specified hour, minute, and second<br>mytime = time(hour=12, minute=30, second=45)<br># Display the time object<br>print(mytime)<br><br># Create a time object with the specified minute<br>mytime = time(minute=15)<br><br># Display the time object<br>print(mytime)<br><br># Access the components of the time object separately<br># Display the hour<br>print(mytime.hour)<br><br># Display the Minute<br>print(mytime.minute)<br><br># Display the Second<br>print(mytime.second)<br><br># Get the current date and time<br>todays_date = datetime.now()<br><br># Calculate the date after adding 90 days<br>dateafter_months = todays_date + timedelta(days=90)<br><br># Display the resulting date<br>print(dateafter_months)<br><br># Calculate the total number of seconds in a month (30 days)<br>seconds_in_a_month = timedelta(days=30).total_seconds()<br><br># Display the result<br>print(&quot;Total seconds in a month:&quot;, seconds_in_a_month)<br><br>date_str = &quot;14.12.2025&quot;<br><br>dt = datetime.strptime(date_str, &quot;%d.%m.%Y&quot;)<br>day_name = dt.strftime(&quot;%A&quot;)<br><br>print(day_name)</pre><pre>#output<br>Date is: 2001-08-08<br>2025-12-14<br>12<br>2025<br>14<br>2025-12-14 21:26:35.364372<br>12:30:45<br>00:15:00<br>0<br>15<br>0<br>2026-03-14 21:26:35.364372<br>Total seconds in a month: 2592000.0<br>sunday</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd64f94d463bfb46620c26c3f7935ad7/href">https://medium.com/media/cd64f94d463bfb46620c26c3f7935ad7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q02WU5J9KZmRUTnL6Zjyhw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0559bd5d3ff7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Math Module]]></title>
            <link>https://medium.com/@datawhizz.26/math-module-fbc3bc949319?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbc3bc949319</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Sun, 14 Dec 2025 19:41:41 GMT</pubDate>
            <atom:updated>2025-12-14T19:41:41.017Z</atom:updated>
            <content:encoded><![CDATA[<p>Python Chapter V</p><blockquote><strong>Essential Math Functions</strong></blockquote><pre>import math as m<br><br># in-built function - no need for importing module<br># Math module we import the module to proceed their objects to use that<br><br>print(round(m.pi))<br>print(max(1,3,4,5))<br>print(min(0,-1,9))<br>print(abs(0-4))<br>print(pow(2,3))<br><br>#math module<br>print(m.ceil(m.pi)) # nearest value<br>print(m.floor(m.pi))#only return the integer<br>print(m.sqrt(16)) #return floating value<br>print(f&quot;Combination of number : {m.comb(5,3)}&quot;)<br>print(m.exp(86))<br>print(m.factorial(5))<br>print(m.fmod(10,5))#return float<br>list_1=[4,5,6]<br>print(m.fsum(list_1))#return float<br>print(m.prod(list_1))#return int<br>print(m.gcd(6,3))#HCF<br>print(&quot;check sqrt &quot;,m.isqrt(13))<br>print(m.perm(5))<br>print(m.remainder(10,5))#return float</pre><pre>#output<br>3<br>5<br>-1<br>4<br>8<br>4<br>3<br>4.0<br>Combination of number : 10<br>2.235246603734715e+37<br>120<br>0.0<br>15.0<br>120<br>3<br>check sqrt  3<br>120<br>0.0</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc452004ff8283a001db1eca5c443564/href">https://medium.com/media/cc452004ff8283a001db1eca5c443564/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9dCoHYdsVq9RwSWPb_5f9g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbc3bc949319" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OOP in Python]]></title>
            <link>https://medium.com/@datawhizz.26/oop-9b05ef580a63?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b05ef580a63</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[principles]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Sun, 14 Dec 2025 06:31:31 GMT</pubDate>
            <atom:updated>2025-12-15T07:53:12.957Z</atom:updated>
            <content:encoded><![CDATA[<h3>OOP</h3><p>Python Chapter IV</p><h3>Class and Object</h3><pre>print(&quot;OOP - Object Oriented Programming&quot;)<br><br># class<br><br>class Fruit:<br>    colour = &quot;Red&quot;<br>Apple = Fruit()<br>print(Apple.colour)<br><br># del object <br>del Apple<br># print(Apple.colour) - Error <br><br># Multiple - object created<br>Dragon_Fruit=Fruit()<br>print(Dragon_Fruit.colour)<br><br>#pass statement<br><br>class Fruit:<br>    pass<br><br># __init__ -&gt; method<br><br>class Fruit:<br>    def __init__(self,colour):<br>         self.colour = colour<br>Apple=Fruit(&quot;Red&quot;)<br>Orange=Fruit(&quot;Orange&quot;)<br><br>print(f&quot;The Apple colour is : {Apple.colour}&quot;)<br><br>print(f&quot;Orange Fruit colour is : {Orange.colour}&quot;)<br><br># Multiple parameter in __init__ function<br><br>class Fruit:<br>    def __init__(self,colour,count):<br>         self.colour = colour<br>         self.count=count<br>Apple=Fruit(&quot;Red&quot;,8)<br>Orange=Fruit(&quot;Orange&quot;,9)<br><br>print(f&quot;The Apple colour is : {Apple.colour}&quot;)<br><br>print(f&quot;Orange Fruit colour is : {Orange.colour}&quot;)<br><br>print(Apple.count)<br><br>#Default value in __init__<br><br>class Fruit:<br>    def __init__(myobject,colour,count=0):<br>         myobject.colour = colour<br>         myobject.count=count<br>Apple=Fruit(&quot;Red&quot;,8)<br>Orange=Fruit(&quot;Orange&quot;)<br><br>print(f&quot;Orange Count : {Orange.count}&quot;)</pre><pre># output<br>OOP - Object Oriented Programming<br>Red<br>Red<br>The Apple colour is : Red<br>Orange Fruit colour is : Orange<br>The Apple colour is : Red<br>Orange Fruit colour is : Orange<br>8<br>Orange Count : 0</pre><h3>Class Properties and Object Properties</h3><blockquote>Properties defined outside methods belong to the class itself (class properties) and are shared by all objects</blockquote><blockquote>Properties defined inside __init__() belong to each object (instance properties).</blockquote><pre>class Person:<br>  species = &quot;Human&quot; # Class property<br><br>  def __init__(self, name):<br>    self.name = name # Instance property<br>  def greet(self):<br>    print(&quot;Hello!&quot;)<br><br>p1 = Person(&quot;John&quot;)<br>p2 = Person(&quot;Tom&quot;)<br><br>#Access <br>print(p1.name)<br>print(p2.name)<br>print(p1.species)<br>print(p2.species)<br>#Modifying Class Properties<br>Person.species=&quot;People&quot;<br>print(p1.species)<br>print(p2.species)<br>#Add New Properties<br>p1.age=39<br>Person.count=1<br>print(p1.age)<br>print(p1.count)<br>print(p1.greet())<br><br># Delete Properties<br>del p1.age<br>print(p1.name) # This works<br># print(p1.age) # This would cause an error<br><br>#del method <br>del Person.greet</pre><pre>#output<br>John<br>Tom<br>Human<br>Human<br>People<br>People<br>39<br>1<br>Hello!<br>None<br>John</pre><h3>The __str__() Method</h3><blockquote>The __str__() method is a special method that controls what is returned when the object is printed</blockquote><pre># without __str__ <br><br>class Person:<br>  def __init__(self, name, age):<br>    self.name = name<br>    self.age = age<br><br>p1 = Person(&quot;Emil&quot;, 36)<br><br>print(p1)<br><br>#output<br>&lt;__main__.Person object at 0x7bd8b4665be0&gt;<br><br>#with __str__ method<br> <br>class Person:<br> def __init__(self, name, age):<br>    self.name = name<br>    self.age = age<br> def __str__(self):<br>    return f&quot;{self.name} ({self.age})&quot;    <br>p1 = Person(&quot;Tobias&quot;, 36)<br>print(p1)<br><br>#output<br>Tobias (36)</pre><h3>Static</h3><pre><br>#Static method<br>class Math:<br>    @staticmethod<br>    def add(a, b):<br>        return a + b<br><br>print(Math.add(10, 5))   # No object needed<br><br><br>class Fruit:<br>    category = &quot;Food&quot;   # static/class variable<br><br>    def __init__(self, name):<br>        self.name = name  # instance variable<br><br>#output<br>15<br>---------------------------------------------------------------------------<br># order of execution<br>class Demo:<br><br>    print(&quot;1. Class is being defined (Static Block)&quot;)   # static-like<br><br>    def __init__(self):<br>        print(&quot;2. Inside __init__ (constructor)&quot;)<br><br>    def normal(self):<br>        print(&quot;3. This is a normal method&quot;)<br><br><br>print(&quot;----Creating object----&quot;)<br>d = Demo()<br><br>print(&quot;----Calling normal method----&quot;)<br>d.normal()<br><br>#output<br>1. Class is being defined (Static Block)<br>----Creating object----<br>2. Inside __init__ (constructor)<br>----Calling normal method----<br>3. This is a normal method<br><br>----------------------------------------------------------------------<br><br><br># def add(self, numbers) -&gt; int: -&gt; it was hint the method return the integer as a output<br>class Calculator:<br>    def add(self, numbers: list) -&gt; int:<br>        total = sum(numbers)<br>        return total<br><br>calc = Calculator()<br>print(calc.add([10,20,30]))<br>#output<br>60</pre><blockquote><strong>If __name__ == “__main__”</strong></blockquote><p>fruit.py</p><pre>def add(a, b):<br>    return a + b<br><br>print(&quot;This is fruit file running&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    print(&quot;Main block working&quot;)<br>    print(add(10, 20))<br><br>#output<br>This is fruit file running<br>Main block working<br>30</pre><p>test.py</p><pre>import fruit<br><br>#output<br>Fruit python</pre><h3>OOP Principle</h3><h4>1. Inheritance</h4><blockquote><strong>Inheritance</strong> allows one class to <strong>reuse properties and methods of another class</strong>.<br>It helps avoid code duplication and supports <strong>reusability</strong>.</blockquote><pre>print(&quot;Inheritance&quot;)<br><br>class Parent:<br>    pass<br>class Child(Parent):<br>    pass</pre><h4>Types of Inheritance</h4><p>— — — — — — — — — — — -</p><blockquote>Single Inheritance</blockquote><pre>class Animal:<br>    def __init__(self,name):<br>        self.name=name<br>class Name_of_Animal(Animal):<br>    def __init__(self,name):<br>        super().__init__(name)<br>        print(self.name)<br>    <br>  <br>        <br># super() → calls the parent class method<br>Dog=Name_of_Animal(&quot;Dog&quot;)<br>Lion=Name_of_Animal(&quot;Lion&quot;)<br><br>#output<br>Dog<br>Lion</pre><blockquote>Multilevel Inheritance</blockquote><pre>&#39;&#39;&#39;<br>class A<br>   |<br>class B<br>   |<br>class C<br>&#39;&#39;&#39;<br>class GrandParent:<br>    def show1(self):<br>        print(&quot;GrandParent&quot;)<br><br>class Parent(GrandParent):<br>    def show2(self):<br>        print(&quot;Parent&quot;)<br><br>class Child(Parent):<br>    def show3(self):<br>        print(&quot;Child&quot;)<br><br>c = Child()<br>c.show1()<br>c.show2()<br>c.show3()<br><br>#output<br>GrandParent<br>Parent<br>Child</pre><blockquote>Multiple Inheritance</blockquote><pre>&#39;&#39;&#39;<br>class A       class B<br>          |<br>       class c<br>&#39;&#39;&#39;<br>class Father:<br>    def skill1(self):<br>        print(&quot;Driving&quot;)<br><br>class Mother:<br>    def skill2(self):<br>        print(&quot;Cooking&quot;)<br><br>class Child(Father, Mother):<br>    pass<br><br>c = Child()<br>c.skill1()<br>c.skill2()<br><br>#output<br>Driving<br>Cooking</pre><blockquote>Hierarchical Inheritance</blockquote><pre>class Parent:<br>    pass<br><br>class Child1(Parent):<br>    pass<br><br>class Child2(Parent):<br>    pass</pre><blockquote>Hybrid Inheritance</blockquote><ul><li><em>Combination of two or more types.</em></li></ul><h4>2. Polymorphism</h4><ul><li>Many Form</li></ul><h4>Types of Polymorphism</h4><blockquote><strong>Method Overriding — Runtime Polymorphism</strong></blockquote><ul><li>Child class changes parent class method.</li></ul><pre>class Animal:<br>    def sound(self):<br>        print(&quot;Animal makes sound&quot;)<br><br>class Dog(Animal):<br>    def sound(self):<br>        print(&quot;Dog barks&quot;)<br>a1 = Dog()<br>a1.sound()<br># a2 = Animal()<br># a2.sound() output - Animal makes sound<br><br>#output<br>Dog barks<br><br># print(isinstance(c, Child))   # True<br># print(isinstance(c, Parent))  # True<br># print(issubclass(Child, Parent))  # True<br>print(isinstance(a1, Dog))   # True<br>print(isinstance(a1, Animal))  # True<br>print(issubclass(Dog,Animal))  # True</pre><blockquote>Method Overloading</blockquote><ul><li>Python Not support this instead they have a *args function</li></ul><h3>Encapsulation</h3><blockquote><strong>Encapsulation</strong> means <strong>binding data (variables) and methods (functions) together</strong> inside a class <strong>and controlling access</strong> to them.</blockquote><blockquote><em>- </em>Data hiding + data protection</blockquote><blockquote>without this</blockquote><pre>class Student:<br> def __init__(self, name, marks):<br>  self.name = name<br>  self.marks = marks<br>s = Student(&quot;John&quot;, 95)<br>s.marks = 200 # Wrong but allowed - Anyone can change data.<br>print(s.marks)<br><br>#output<br>200</pre><h3>Access Modifiers</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccd9da281cd21fbe6cd16119d5f9a1d2/href">https://medium.com/media/ccd9da281cd21fbe6cd16119d5f9a1d2/href</a></iframe><h3>1. Public Members</h3><pre>class Employee:<br>    def __init__(self, name):<br>        self.name = name   # public<br>e = Employee(&quot;Ram&quot;)<br>print(e.name)   # Allowed<br><br>#output<br>Ram</pre><h3>2. Protected Members _</h3><pre>class Bank:<br>    def __init__(self):<br>        self._balance = 5000<br>class Customer(Bank):<br>    def show(self):<br>        print(self._balance)<br>c = Customer()<br>c.show()<br><br>#output<br>5000</pre><h3>3. Private Members __</h3><pre>class Bank:<br>    def __init__(self):<br>        self.__balance = 10000<br>    def show_balance(self):<br>        print(self.__balance)<br>b = Bank()<br>b.show_balance()   # work perfectly<br># print(b.__balance) Error<br><br>#output<br>10000</pre><h3>Name Mangling</h3><p>Private variables are renamed internally:</p><pre>print(b._Bank__balance)   # Works but not recommended<br><br>#output<br>10000</pre><h3>Getter and Setter</h3><pre>class Account:<br>    def __init__(self):<br>        self.__balance = 0<br>    def get_balance(self):<br>        return self.__balance<br>    def set_balance(self, amount):<br>        if amount &gt;= 0:<br>            self.__balance = amount<br>        else:<br>            print(&quot;Invalid amount&quot;)<br>a = Account()<br>a.set_balance(5000)<br>print(a.get_balance())<br><br>#output<br>5000</pre><h3>Using @property (Pythonic Way )</h3><pre>class Account:<br>    def __init__(self):<br>        self.__balance = 0<br>    @property<br>    def balance(self):<br>        return self.__balance<br>    @balance.setter<br>    def balance(self, amount):<br>        if amount &gt;= 0:<br>            self.__balance = amount<br>        else:<br>            print(&quot;Invalid&quot;)<br>a = Account()<br>a.balance = 3000<br>print(a.balance)<br><br>#output<br>3000</pre><h3>Python Inner Classes</h3><ul><li>An <strong>inner class</strong> is a <strong>class defined inside another class</strong>.</li><li>It is used when the inner class is <strong>closely related</strong> to the outer class and <strong>should not be used independently</strong>.</li></ul><p>Syntax</p><pre>class Outer:<br>    class Inner:<br>        pass</pre><pre>class Car:<br>    a = 90<br>    class Engine:<br>        def __init__(self, outer_obj):<br>            self.outer = outer_obj<br>        <br>        def engine_type(self):<br>            print(&quot;Petrol Engine&quot;)<br>            print(self.outer.a)<br><br>c = Car()<br><br># Access Inner Class Using Outer Class Object<br># Accessing Outer Class from Inner Class<br>e = Car.Engine(c)<br>e.engine_type()<br><br>#output<br>Petrol Engine<br>90</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lifYFKF4Jfgon8lnSdgsTQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b05ef580a63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exception Handling]]></title>
            <link>https://medium.com/@datawhizz.26/exception-handling-76d5594d4ad4?source=rss-404c372f7bb7------2</link>
            <guid isPermaLink="false">https://medium.com/p/76d5594d4ad4</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[fullstack-development]]></category>
            <category><![CDATA[exception-handling]]></category>
            <category><![CDATA[personal-growth]]></category>
            <dc:creator><![CDATA[Datawhiz]]></dc:creator>
            <pubDate>Sat, 13 Dec 2025 18:23:56 GMT</pubDate>
            <atom:updated>2025-12-15T07:44:57.587Z</atom:updated>
            <content:encoded><![CDATA[<p>Python Chapter III</p><pre><br># The try block lets you test a block of code for errors.<br><br># The except block lets you handle the error.<br><br># The else block lets you execute code when there is no error.<br><br># The finally block lets you execute code, <br># regardless of the result of the try- and except blocks.<br><br>try:<br>  print(x)<br>except:<br>  print(&quot;An exception occurred&quot;)<br>finally:<br>    print(&quot;Exit&quot;)<br><br>try:<br>  print(x)<br>except NameError:<br>  print(&quot;Variable x is not defined&quot;)<br>except:<br>  print(&quot;Something else went wrong&quot;)<br><br># You can use the else keyword to define a block of <br># code to be executed if no errors were raised:<br><br>try:<br>  print(&quot;Hello&quot;)<br>except:<br>  print(&quot;Something went wrong&quot;)<br>else:<br>  print(&quot;Nothing went wrong&quot;)<br>  <br># Raise an exception<br># As a Python developer you can choose to throw an <br># exception if a condition occurs.<br><br># To throw (or raise) an exception, use the raise keyword.<br><br>x = -1<br><br>if x &lt; 0:<br>  raise Exception(&quot;Sorry, no numbers below zero&quot;)<br><br><br>#output<br>&lt;function &lt;lambda&gt; at 0x7ce26bc64fe0&gt;<br>Exit<br>&lt;function &lt;lambda&gt; at 0x7ce26bc64fe0&gt;<br>Hello<br>Nothing went wrong<br>---------------------------------------------------------------------------<br>Exception                                 Traceback (most recent call last)<br>/tmp/ipython-input-2432679577.py in &lt;cell line: 0&gt;()<br>     40 <br>     41 if x &lt; 0:<br>---&gt; 42   raise Exception(&quot;Sorry, no numbers below zero&quot;)<br><br>Exception: Sorry, no numbers below zero</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uVDg1aJ51vBb2oJKtFrj6g.png" /></figure><h3>Names of Exception</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7a27cbcb56256f79dc0967ced2826c1/href">https://medium.com/media/f7a27cbcb56256f79dc0967ced2826c1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76d5594d4ad4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>