<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jaswant Vaddi</title>
    <description>The latest articles on Forem by Jaswant Vaddi (@vaddijaswant).</description>
    <link>https://forem.com/vaddijaswant</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1271257%2Fc48e55bb-f137-4cfa-bb1d-df5e373853f0.png</url>
      <title>Forem: Jaswant Vaddi</title>
      <link>https://forem.com/vaddijaswant</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vaddijaswant"/>
    <language>en</language>
    <item>
      <title>Help Me Simplify Virtual Environments with 'pve' – Community Input Needed!</title>
      <dc:creator>Jaswant Vaddi</dc:creator>
      <pubDate>Sun, 23 Feb 2025 14:27:20 +0000</pubDate>
      <link>https://forem.com/vaddijaswant/help-me-simplify-virtual-environments-with-pve-community-input-needed-2pec</link>
      <guid>https://forem.com/vaddijaswant/help-me-simplify-virtual-environments-with-pve-community-input-needed-2pec</guid>
      <description>&lt;p&gt;Hey everyone! As a beginner, I’ve found setting up virtual environments tricky due to varying commands across systems. They’re crucial for project organization, so I’m working on making them easier for newbies like me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description of My Package:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’ve started building pve, a small package to simplify virtual environments. It has two commands: &lt;code&gt;pve create {env_name}&lt;/code&gt; to make a new environment and &lt;code&gt;pve start {env_name}&lt;/code&gt; to activate it.&lt;/p&gt;

&lt;p&gt;Current Issue:&lt;/p&gt;

&lt;p&gt;The package is working as expected in Windows but The start command isn’t activating environment in &lt;strong&gt;MAC OS&lt;/strong&gt;, likely due to cross-platform issues. I’d love insights from experienced devs—any tips on fixing activation or handling system differences?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/VADDIJASWANT/PVE" rel="noopener noreferrer"&gt;GITHUB&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>pythonpackage</category>
      <category>virtualenv</category>
      <category>help</category>
    </item>
    <item>
      <title>JavaScript: Mastering Asynchrony in a Single Thread</title>
      <dc:creator>Jaswant Vaddi</dc:creator>
      <pubDate>Fri, 15 Mar 2024 17:00:36 +0000</pubDate>
      <link>https://forem.com/vaddijaswant/javascript-mastering-asynchrony-in-a-single-thread-55h5</link>
      <guid>https://forem.com/vaddijaswant/javascript-mastering-asynchrony-in-a-single-thread-55h5</guid>
      <description>&lt;p&gt;Before we delve into asynchronous JavaScript, let’s first discuss how the JavaScript compiler performs operations.&lt;/p&gt;

&lt;p&gt;JavaScript is often referred to as a single-threaded language, meaning it cannot delegate work across multiple threads. Instead, it must execute each operation one by one in a single thread.&lt;/p&gt;

&lt;p&gt;This single thread operates like an array. It contains a set of operations to perform, and the JavaScript engine uses push and pop operations to add or remove functions from the stack.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function consoleLog(){
    console.log("testing")
}
function firstFunction(){
    consoleLog()
}
firstFunction();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the JavaScript engine, which is always checking for functions to run, initially adds firstFunction to the stack.&lt;/p&gt;

&lt;p&gt;Then, it sees that we are calling the consoleLog function. Before completing this function, it adds consoleLog to the top of the stack for execution. &lt;/p&gt;

&lt;p&gt;Next, it encounters the console.log() function, which it then adds to the top of the stack. After executing console.log(), it pops this function from the stack. Since there are no remaining parts of the consoleLog function, it pops consoleLog from the stack. Finally, it pops firstFunction from the stack.&lt;/p&gt;

&lt;p&gt;Now, let’s talk about asynchronous JavaScript.&lt;/p&gt;

&lt;p&gt;An asynchronous function is one that cannot be executed completely and return a value directly because some task within it takes a significant amount of time.&lt;/p&gt;

&lt;p&gt;A prime example of asynchronous functions are API calls. These calls connect with servers, which then connect with the required resources and return that resource. This process usually takes more time than we might expect.&lt;/p&gt;

&lt;p&gt;Imagine you are running a function, and then there is an API call to get some data from a server. If this call is not asynchronous, your code is forced to wait for the entire duration of the call without doing anything else. Then, it must complete the rest of the function. This can take a lot of time.&lt;/p&gt;

&lt;p&gt;So, what does JavaScript do for these asynchronous functions?&lt;/p&gt;

&lt;p&gt;These functions are usually browser functions, so the JavaScript engine sends these functions directly to the browser to perform these actions while it continues as usual with the rest of the code.&lt;/p&gt;

&lt;p&gt;The browser performs the asynchronous function completely and sends a message to the task queue indicating that this call is completed and provides the return value.&lt;/p&gt;

&lt;p&gt;The JavaScript engine is always on the lookout for any function to be performed and to be added to the stack. &lt;/p&gt;

&lt;p&gt;For instance, let’s say we added a click event to an HTML button element where this event triggers a function. As soon as we click, the engine knows to perform the click event function and adds that to the stack. The engine is constantly on the lookout for functions to be performed and, once it sees that the stack is empty, it also checks the task queue sent by the browser to see if there is any function to perform.&lt;/p&gt;

&lt;p&gt;The engine performs all the functions that are in the stack and then performs the functions given by the browser queue. A great example to observe this phenomenon is this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("a")
setTimeout(()=&amp;gt; {console.log("b")},0)
console.log("c")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can try to run this code and see the order in which “a”, “b”, and “c” are logged to the console.&lt;/p&gt;

&lt;p&gt;Here is a small explanation for it: &lt;br&gt;
When we run this code, the first function to go to the stack is console.log("a"), which gets executed and logs “a” to the console.&lt;br&gt;
The second line added to the stack is the setTimeout function. Once this browser API function is triggered, it sends the contents in it to the browser to deal with directly and removes this call from the stack.&lt;/p&gt;

&lt;p&gt;The browser immediately returns a message to the task queue saying that you have to perform console.log("b").&lt;/p&gt;

&lt;p&gt;But our JavaScript engine will first check if there is any function which is required to be added to the stack before checking the queue. It sees we need to perform console.log("c"), and it doesn’t know there is a message in the queue yet.&lt;/p&gt;

&lt;p&gt;Once it logs “c” to the console, it reads the task queue message and logs “b” to the console.&lt;/p&gt;

&lt;p&gt;This is my basic understanding and explanation of what asynchronous is and how JavaScript manages it in a single thread.&lt;/p&gt;

&lt;p&gt;If there are some more good examples which you think of are know, which showcases asynchronous of javascript please share them&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is custom attribute</title>
      <dc:creator>Jaswant Vaddi</dc:creator>
      <pubDate>Sat, 03 Feb 2024 14:28:27 +0000</pubDate>
      <link>https://forem.com/vaddijaswant/what-is-custom-attribute-f3a</link>
      <guid>https://forem.com/vaddijaswant/what-is-custom-attribute-f3a</guid>
      <description>&lt;h2&gt;
  
  
  Table Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction to Custom Attributes&lt;/li&gt;
&lt;li&gt;Difference Between Data-Prefixed and Non-Prefixed Custom Attributes&lt;/li&gt;
&lt;li&gt;Syntax for Data Attributes&lt;/li&gt;
&lt;li&gt;Accessing and Modifying Data Attribute Values&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Recently for some reason I had to use data attribute in my project, then I have wondered can I give a custom attribute to html tag without ‘data- ‘ as prefix then I did some digging online it took some time for me to find relevant details, in this post first lets go through what are custom attribute how we use then and some details regarding its syntax and also why we are not use custom attributes directly without ‘data- ‘ prefix, so lets start&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction to Custom Attributes
&lt;/h3&gt;

&lt;p&gt;I am sure you know what are attributes in HTML tags like id, class, onClick etc  these are predefined attributes for the HTML tags, if there is some data that we want to store on HTML without linking to a Javascript property then we use data attributes to be honest there is some other uses of data attributes instead of just storing content in HTML we can also use this as a CSS selector, this just some normal overview of what is data attribute&lt;/p&gt;

&lt;h3&gt;
  
  
  Difference Between Data-Prefixed and Non-Prefixed Custom Attributes
&lt;/h3&gt;

&lt;p&gt;well on outside there is not much difference except for the prefix but inside the HTML DOM there is significant difference, so when we use ‘data-’  as prefix HTML knows we are using data attributes and it stores all the attributes which are prefixed with ‘data-’  in a particular property in its DOM known as ‘dataSet’, but when we don’t use the prefix it doesn’t know that they are custom attributes,  this might lead to some validation and compatibility issues with different browsers so we are generally recommended to use ‘data-’ prefix&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax for Data attributes
&lt;/h3&gt;

&lt;p&gt;syntax for data attributes is simple we will write the name of custom attribute with ‘data-’ as prefix&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;article&lt;/span&gt;
    &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;'history'&lt;/span&gt;
    &lt;span class="na"&gt;data-type=&lt;/span&gt;&lt;span class="s"&gt;'history'&lt;/span&gt;
    &lt;span class="na"&gt;data-period=&lt;/span&gt;&lt;span class="s"&gt;'19th century'&lt;/span&gt;
    &lt;span class="na"&gt;data-index-number=&lt;/span&gt;&lt;span class="s"&gt;20&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any type of value you assign to data attribute it will always treat that data attribute as string when we try to access that in Javascript&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessing and Modifying Data Attribute Values
&lt;/h3&gt;

&lt;p&gt;I am sure you remember that in DOM object all the data attributes are stored in dataset property we can access these data attributes in ‘dataset‘ property&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;history&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//or you can use &lt;/span&gt;
&lt;span class="c1"&gt;// const element = document.querySelector("#history")&lt;/span&gt;

&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "history"&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;period&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "19th century"&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "20" // this is string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you have saw how I accessed a data attribute ‘index-number’ we are accessing it in ‘dataset’ using ‘indexNumber‘&lt;/p&gt;

&lt;p&gt;all the names of data attributes after ‘data-’ are divided by - if there is any in the name and are converted into camelCased&lt;/p&gt;

&lt;p&gt;small question from my side what will happen if I have a data attribute which is data-Number, how to do you think we have to access that Number in dataset please let me know in comments&lt;/p&gt;

&lt;p&gt;same way as we get the data attributes value we can set them&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;science&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;there is also another way get and set the data attribute which is using getAttribute and setAttribute&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope this blogs give you clarity on data attributes and if you have any comments you can ask in comments&lt;/p&gt;

&lt;p&gt;sources:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes#issues"&gt;MDN DOCS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;ChatGPT,BingAI&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Summary:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Custom attributes in HTML, known as data attributes, allow storing additional information on HTML elements without linking to JavaScript properties.&lt;/li&gt;
&lt;li&gt;It's recommended to prefix custom attributes with 'data-' to ensure proper recognition and handling within the HTML DOM, this will resolve any potential issues which are raised by browsers&lt;/li&gt;
&lt;li&gt;Data attributes follow a simple syntax where the custom attribute name is prefixed with 'data-'.&lt;/li&gt;
&lt;li&gt;Don’t forget regarding the camelCase&lt;/li&gt;
&lt;li&gt;Accessing and modifying data attribute values can be done using the 'dataset' property or via getAttribute and setAttribute methods.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>html</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Python Comprehensions: A Short Overview</title>
      <dc:creator>Jaswant Vaddi</dc:creator>
      <pubDate>Thu, 01 Feb 2024 16:13:52 +0000</pubDate>
      <link>https://forem.com/vaddijaswant/python-comprehensions-a-short-overview-39l1</link>
      <guid>https://forem.com/vaddijaswant/python-comprehensions-a-short-overview-39l1</guid>
      <description>&lt;h2&gt;
  
  
  Table Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction to Python Comprehensions&lt;/li&gt;
&lt;li&gt;Syntax of Comprehensions&lt;/li&gt;
&lt;li&gt;Adding Extra Conditions&lt;/li&gt;
&lt;li&gt;Pros and Cons&lt;/li&gt;
&lt;li&gt;When to Use Comprehensions vs. For Loops&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hi guys, For some reason Initially I never understood comprehensions in python, I tried to avoid using that and mostly used for loop in its place, I thought that comprehensions are just fancy way of writing the same thing we do in loop(actually it is sort of), when I started writing more code in python slowly I was also tired of writing the complete loops for every small operations so I started using comprehensions to be honest I only used them mostly for lists, but I still used to had one doubt is there any other advantage of using the comprehensions instead of traditional loops. after getting answer to it I thought I have to write about it and share it so here we Go&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Introduction to Python Comprehensions
&lt;/h2&gt;

&lt;p&gt;Comprehensions in Python provide a short and readable way to generate sequences of data. They are a single-line loop that creates a new list, dictionary, set, or generator.&lt;/p&gt;

&lt;p&gt;well this above line is definition according to AI but in simple terms we use comprehensions to create a list, dictionary, sets or generator from a iterable data&lt;/p&gt;

&lt;p&gt;Some of the benefits of using the Comprehensions include easier to read, write and cleaner code with most important on more EFFICIENT and FASTER than traditional loops&lt;/p&gt;

&lt;p&gt;Python supports four types of comprehensions: list, dictionary, set, and generator comprehensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Syntax of Comprehensions
&lt;/h2&gt;

&lt;p&gt;The general syntax of a comprehension is: &lt;strong&gt;&lt;code&gt;[expression for item in iterable]&lt;/code&gt;&lt;/strong&gt;. This will create a new list resulting from the &lt;strong&gt;&lt;code&gt;expression&lt;/code&gt;&lt;/strong&gt; for each &lt;strong&gt;&lt;code&gt;item&lt;/code&gt;&lt;/strong&gt; in the &lt;strong&gt;&lt;code&gt;iterable&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Examples of each type of comprehension
&lt;/h3&gt;

&lt;p&gt;Here are examples of each type of comprehension:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;List comprehension: &lt;strong&gt;&lt;code&gt;[x ** 2 for x in range(10)]&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Dictionary comprehension: &lt;strong&gt;&lt;code&gt;{x: x ** 2 for x in range(10)}&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Set comprehension: &lt;strong&gt;&lt;code&gt;{x **2 for x in range(10)}&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Generator comprehension: &lt;strong&gt;&lt;code&gt;(x ** 2 for x in range(10))&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Adding Extra Conditions
&lt;/h2&gt;

&lt;p&gt;You can add conditions to the comprehensions to filter the results. The syntax is: &lt;strong&gt;&lt;code&gt;[expression for item in iterable if condition]&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example, &lt;strong&gt;&lt;code&gt;[x ** 2 for x in range(10) if x % 2 == 0]&lt;/code&gt;&lt;/strong&gt; creates a list of squares for even numbers only.&lt;/p&gt;

&lt;p&gt;two small question if you want to solve&lt;/p&gt;

&lt;p&gt;assume you have a list of words and a string representing a set of letters, create a function that generates an iterable containing only the words from the list that start with any of the letters in the provided string.&lt;/p&gt;

&lt;p&gt;create a list which contains all the common items between two lists&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Pros and Cons
&lt;/h2&gt;

&lt;p&gt;the main advantages of using Comprehensions are they are faster, readable and more efficient than traditional loops&lt;/p&gt;

&lt;p&gt;But there is also a small drawback for comprehension if the logic is complex then it will get harder to read and understand in these situations it might be better to use traditional loops you can check the example in next section for reference&lt;/p&gt;

&lt;h2&gt;
  
  
  5. When to Use Comprehensions vs. For Loops
&lt;/h2&gt;

&lt;p&gt;While comprehensions are more concise, traditional loops still are more flexible and can handle more complex tasks.&lt;/p&gt;

&lt;p&gt;so in the cases where task is complex, involves using of nested loops or any other complex logic then Explicit For loops are more appropriate in this kind of situations&lt;/p&gt;

&lt;p&gt;A small example to show case this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;nested_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;span class="n"&gt;flattened&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;sublist&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;nested_list&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sublist&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sublist&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;flattened&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;nested_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;span class="n"&gt;flattened&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;sublist&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;nested_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sublist&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sublist&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;flattened&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;flattened&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from this example I am sure you can see the difference between using Comprehensions and traditional loops, actually both are doing the same but check the readability it will take more time for you to simply understand whats happening when you check that comprehensions&lt;/p&gt;

&lt;p&gt;So with this small article I hope it clears any doubts or confusions you have on comprehensions and you will be fully comfortable with any situation where you need to use comprehensions.If you have any questions feel free to ask regarding it in comments&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>datastructures</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
