<?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 Shovit Kafle on Medium]]></title>
        <description><![CDATA[Stories by Shovit Kafle on Medium]]></description>
        <link>https://medium.com/@shovitkafle?source=rss-79ca39c3a734------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kq3yIha_fvgt41uNjkp92A.png</url>
            <title>Stories by Shovit Kafle on Medium</title>
            <link>https://medium.com/@shovitkafle?source=rss-79ca39c3a734------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:04:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shovitkafle/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[Scrum Explained: Building Better Software Without Getting Stuck in the Plan]]></title>
            <link>https://medium.com/@shovitkafle/scrum-explained-building-better-software-without-getting-stuck-in-the-plan-0065183b53c7?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/0065183b53c7</guid>
            <category><![CDATA[scrum-framework]]></category>
            <category><![CDATA[sprint-planning]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[agile-methodology]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Sat, 24 Oct 2026 17:26:51 GMT</pubDate>
            <atom:updated>2026-10-24T17:26:51.992Z</atom:updated>
            <content:encoded><![CDATA[<p>Agile, Scrum, sprints, user stories and the real-world takeaways that every developer should know before.</p><p>A friendly, hands-on reference for developers, product teams and all those who seek to make shift in requirements into working software.</p><h3>The problem with a “perfect” plan</h3><p>Suppose that your team has been working for weeks on a feature. Architecture has been cleaned up, tickets are close to completion and we’re all feeling good. Then the client asks, “Is there any way we could adjust that?” Suddenly, one small request has an impact on the database, the API, the UI, tests and delivery date.</p><p>That’s a typical situation in software development. It’s not that clients change their minds. The real issue is when we take for granted that they never will.</p><p>So, this is where Agile makes sense. We don’t think of a plan as something we have to do at all costs, but we build a little, then gather feedback and make some changes. In other words: Create something valuable, learn from it and make the next version better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*58J-zeYkFUkDLF_MXDDsCw.png" /><figcaption>Figure 1. Waterfall emphasizes sequential stages; Agile emphasizes shorter feedback loops. Both can be appropriate, depending on the work.</figcaption></figure><h3>First, Agile and Scrum are not the same thing</h3><p>I used to read the terms Agile and Scrum used interchangeably. They are interrelated but at different levels. Agile is a collection of values and principles, it’s a way of developing software. One lightweight framework that helps teams adopt empirical, iterative working is Scrum.</p><p>The Agile Manifesto was first released in 2001, and highlights the importance of people and collaboration, useful software, working with customers, and adapting to change. It’s not to say that documentation is not relevant, or that planning should go away! It implies that where there is a compromise, value and learning should be the basis for decision making.</p><p>Scrum brings that notion to life. Teams strive for a Product Goal, choose a smaller Sprint Goal, create a Done Increment, review the results, and change. The key is not to go fast, just to go fast. It’s getting closer to evidence.</p><h3>How Scrum actually works</h3><p>Sprint is a short period of time — one month or less. A good number of teams select one or two weeks, however there’s not any one perfect time frame. The idea is to establish a consistent pace of progress where there is something that can be demonstrated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cp1XYAjiGodo2T4ZFCNdg.png" /><figcaption>Figure 2. A simplified Scrum rhythm. The Sprint contains planning, ongoing work, Daily Scrums, the review, and the retrospective.</figcaption></figure><p>There are three roles in the Scrum Team: the Product Owner, Scrum Master, and Developers. The Product Owner is responsible for maximizing value of the product and maintaining the Product Backlog. The Scrum Master is responsible for educating the team about Scrum and eliminating the impediments. The usable Increment is developed by the plan of the developers. These are not three job titles, or three people, but accountabilities.</p><h3>The five Scrum events</h3><p>· Sprint: the container in which work moves toward the Sprint Goal.</p><p>· Sprint Planning: agree why the Sprint matters, what can be done, and how the team will begin.</p><p>· Daily Scrum: a 15-minute event for Developers to inspect progress toward the Sprint Goal and adapt their plan.</p><p>· Sprint Review: inspect the result with stakeholders and discuss what should happen next.</p><p>· Sprint Retrospective: improve how the team works, not just what it builds.</p><p>One important detail: a Sprint Review is not just a demo, and the Daily Scrum is not a status report to a manager. Both are opportunities to learn and make better decisions.</p><h3>The three artifacts</h3><p>Product Backlog is an ordered, changing list of work to be done that will enhance the product. The Sprint Goal is included in the Sprint Backlog along with the Product Backlog items that have been selected for the Sprint, and the plan for how to do the work. The Increment is the product that has been integrated and is usable and conforms to the Definition of Done. Along with these artifacts, Scrum includes commitments: Product Goal, Sprint Goal and Definition of Done.</p><h3>User stories: turning an idea into useful work</h3><p>This is what really counts once you start using Jira and begin to work on a feature. A large requirement, e.g. build a ride-sharing app, is not something that a team can provide in one Sprint. We must dissect the problem; break it up into manageable chunks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*em0NPrQCyBb8b-NkXmr0vQ.png" /><figcaption>Figure 3. An example hierarchy: one initiative can contain multiple epics, which are broken into smaller user stories. This hierarchy is a common product-planning convention, not a required Scrum artifact.</figcaption></figure><p>The basic form of a user story is: “As a [user], I want [capability], so that [benefit].” For instance: “Commuter needs to be able to see the estimated time of arrival of nearby drivers to make a decision to book a ride.”</p><p>The team can now discuss what this means. Display the minutes or the route? What’s the problem without the drivers? What should be the frequency of ETA update? That discussion is more useful than a ticket with the words “add ETA API.”</p><p>A good story should meet the INVEST criteria — Independent, Negotiable, Valuable, Estimable, Small and Testable. The 3 Cs also are helpful: Card (brief statement), Conversation (shared understanding), and Confirmation (acceptance criteria). These are not required Scrum practices, but are useful user story practices.</p><p>Acceptance criteria for our ETA example might be: Display the minimum ETA if there is a driver near the car, otherwise display “No drivers nearby.” This allows to write sensible tests rather than engage in post-development discussions about expectations.</p><h3>Prioritization: not every feature deserves this Sprint</h3><p>A common mistake is treating every new feature as equally urgent. Product development is really about choosing the next most valuable thing under real constraints. The PDF notes several useful prioritization methods:</p><p>· MoSCoW: separate Must-have, Should-have, Could-have, and Won’t-have-for-now items.</p><p>· Value vs. Effort: spot quick wins and identify high-value work that needs more investment.</p><p>· RICE: compare Reach × Impact × Confidence ÷ Effort when rough quantitative scoring is useful.</p><p>· Kano: distinguish basic expectations from performance improvements and unexpected delights.</p><p>None of these scores makes the decision for you. Use them to make trade-offs visible, then apply product judgment. If a feature does not solve a real user problem, moving it into the next Sprint does not magically create value.</p><h3>Scrum vs. Kanban: which one should I use?</h3><p>Scrum is built around fixed-length Sprints, a Sprint Goal, and regular inspection points. Kanban focuses on visualizing work, managing flow, and limiting work in progress. Kanban can work with a continuously replenished backlog, so it is incorrect to say it has no backlog by definition. Neither approach is automatically better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qCg3oJ96wWpwqykk1HseZg.png" /><figcaption>Figure 4. Simplified board examples. Scrum adds a Sprint cadence; Kanban emphasizes flow and work-in-progress limits.</figcaption></figure><p>For a product team building a major feature with a shared short-term objective, Scrum might help. For a support or platform team handling unexpected production work, Kanban might fit the flow better. Teams can also combine practices deliberately, but mixing names alone is not a process improvement.</p><h3>Estimation is a conversation, not a promise</h3><p>Story points are generally used to compare the size, complexity, and uncertainty relative to each other. They do not represent hours in disguise, and should not be compared between teams. Velocity can be used to predict the performance of a team over a period of time, but it is not a good individual performance measure.<br>The important question when estimating a feature is not just “How many days will it take? It is also, “What are the things that we don’t yet know? A short spike or proof of concept may be a better way of decreasing uncertainty than debating whether the work is five or eight points.</p><h3>What this looks like in a real backend project</h3><p>Let’s say we are creating a wallet to bank transfer functionality. An alluring solution is to produce a single vast ticket that incorporates validations, external API integration, transaction states, notifications, dashboards, and reconciliation. This is hard to review, test and safely deliver.<br>Instead, try to define the user action, draw the flow and divide the action into slices: validate account, initiate transfer, handle reliable state, present result to user. Explicit edge cases and acceptance criteria for each slice. Idempotency, failure handling, authorization, auditability and accurate financial state are also elements of working software for a payments system, not just successful HTTP 200 response.<br>The larger lesson I get from Agile is not to just chop the workload up into smaller chunks of work. Slice it up into more manageable chunks of credible worth. If there is not an end-to-end use for a tiny endpoint, it does not automatically mean it is a valuable Increment.</p><h3>Mistakes that make Scrum feel like extra meetings</h3><p>· Calling the Daily Scrum a meeting where everyone reports to the team lead.</p><p>· Starting a Sprint without a clear Sprint Goal.</p><p>· Assuming a new request can never be discussed or scope can never be renegotiated during a Sprint.</p><p>· Measuring success by the number of tickets closed rather than usable value delivered.</p><p>· Skipping retrospectives because “we are too busy.”</p><p>· Treating the product backlog as a fixed contract instead of an evolving picture of the product.</p><p>Scrum does not eliminate uncertainty. It helps expose it earlier, when there is still time to act. If a team is doing all the ceremonies but not learning, it has adopted the calendar without the mindset.</p><h3>My takeaway</h3><p>Agile isn’t about less documentation, fast at any cost, or “yes, but?”. Scrum is not a magic process to make a weak team. Both make sense when the team is ready to be transparent, work closely together, and adapt when presented with evidence.<br>There is one thing that we should remember, that our job is not to save the original plan. Our task is to develop the correct product, useful step by step, testable step by step.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0065183b53c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everything about Color Theory]]></title>
            <link>https://medium.com/@shovitkafle/everything-about-color-theory-753141af4466?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/753141af4466</guid>
            <category><![CDATA[color-theory]]></category>
            <category><![CDATA[colors]]></category>
            <category><![CDATA[psychology]]></category>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Tue, 09 Dec 2025 11:52:35 GMT</pubDate>
            <atom:updated>2025-12-09T11:52:35.177Z</atom:updated>
            <content:encoded><![CDATA[<p>Analogous Colors: Colors that are closely interrelated in color wheel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*PNpxwTYHcd0rO0bL.png" /></figure><h4>Primary:</h4><p>Red, Green, Yellow (for papers) -&gt; <strong>Focus </strong>and Red, Green, Blue (for digital media)</p><h4>Secondary: Mix of primary</h4><p>Red + Yellow <strong>Orange</strong></p><p>Yellow + Blue <strong>Green</strong></p><p>Blue + Red <strong>Purple / Violet</strong></p><h4>Tertiary: Mix of Primary and Secondary</h4><p>Red + Orange <strong>Red-Orange</strong></p><p>Orange + Yellow <strong>Yellow-Orange</strong></p><p>Yellow + Green <strong>Yellow-Green</strong></p><p>Green + Blue <strong>Blue-Green</strong></p><p>Blue + Purple <strong>Blue-Purple</strong> (a.k.a. Blue-Violet or Indigo)</p><p>Purple + Red <strong>Red-Purple</strong> (a.k.a. Red-Violet or Magenta-ish)</p><h3>HSV</h3><p>Hue: Hue is any color on wheel with maximum saturation</p><p>Saturation: Directly proportional to vibrancy i.e. saturated means vibrant and unsaturated means dull</p><p>Value: We meant shade, tint and tone</p><p>Hue + Black <strong>Shade</strong></p><p>Hue + White <strong>Tint</strong></p><p>Hue + Grey <strong>Tone</strong></p><p>Color Wheel is split in two temperatures: <strong>Warm (fire) and Cool (peace)</strong></p><h3>Color Psychology</h3><p>It shows power, emotions and influence the viewing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*CS7MKmh0PXJwFseBc1f2iQ.png" /></figure><h4>Red (Passion, strength power)</h4><ol><li>Draws attention, pulls eyes easily, used mostly in buttons.</li></ol><p>2. Also alarms appetite, so it is used by food brands.</p><p>3. It is bold</p><h4>Orange (Optimism, Creativity and Warmth)</h4><ol><li>Combines energy of red and yellow, shows enthusiasm.</li><li>Keeps the same bright energy as red. Highlights best with blue.</li><li>Provides a fresh feeling and sense of contrast.</li></ol><h4>Yellow (Happiness, energy and friendliness)</h4><ol><li>Least used in design as can be overused.</li><li>Great for grabbing decision in news.</li><li>Yellow is hard to see in text as it is very intentional if someone use.</li><li>Evoke happiness and shows youthful vibes.</li><li>Mostly used in child products and is not used in healthcare.</li></ol><h4>Green (Nature, Growth and Serenity)</h4><ol><li>Clean, fresh, nature and freshness.</li><li>Used in Financial industry for showing positivity. Also, used in healthcare.</li><li>It is mix of nature and success.</li></ol><h4>Cyan (Clean, Expressive, Productive)</h4><ol><li>Mixture of green and blue</li><li>Shows cleanliness and self-expression.</li><li>Mostly used in biotech startups to show optimism.</li></ol><h4>Blue (Calm, trust and stability)</h4><ol><li>Most commonly used color as it shows stability and calmness.</li><li>Mostly used in banks and manufacturing industry. Also used in health industry. It shows more trust.</li><li>Shades of blue are also used as background, as it is most versatile in wheel and chill in nature.</li></ol><h4>Purple (Luxury, Sincerity and Elegant)</h4><ol><li>Royalty and sophistication. So, used in hospitality and health care industry.</li><li>Mix of love and passion with stability of blue.</li><li>It shades are used in duotones and youthful vibrant brands.</li><li>It gives richer vibrant vibes in photos.</li><li>Takes more space in design than yellow.</li></ol><h4>Pink (Romance and feminity)</h4><ol><li>Romance, love and simpler time. Shows more femininity.</li><li>Lighter version are used much than darker version.</li><li>Pinks draws eyes but cooler color calms it down.</li></ol><h4>Color Harmony</h4><p>Color that works together so it looks balanced and appealing. It is used to make color palates that simply works.</p><p>First -&gt; Complementary (Pairs of color directly opposite) (Especially for contrast) Eg: Red and Green, Orange and Blue i.e. they are opposite in color wheel.</p><p>Second -&gt; Analogous (Pair of main color in wheel that sits next to it). Eg: green and light green, magenta and blue purple i.e. they all work naturally together. All color must role to have saturation and gradient.</p><p>Third -&gt; Monochromatic (One basic color (hue) and have different shades, tones and tints). It looks simple. Eg: blue but in different tints, tones and shades, illustration of pumpkin to show depths in different shades.</p><p>Fourth -&gt; Triadic (Three colors that are evenly spaced in wheel that form a triangle). Eg: Green, orange and purple, red, yellow and blue, etc. They all works evenly and donot overpower other color.</p><p>Fifth -&gt; Tetradic (One dominant color and other three as accent). Eg: yellowish green, yellowish orange, purply blue and magenta. All of these are vibrant so only one of them is used to overpower the used. If we dont want super vibrant we can use different tints and tones.</p><h3>RGB and CMYK</h3><p>We must know the needs of our projects that end up on; to be printed or to show on the screen. RGB means additive color i.e. if we combine all it becomes white. CMYK means subtractive color i.e. if we combine all it becomes black. CMYK is limited to RGB, so RGB is more brighter. So, we only use RGB if it is limited to screen only.</p><h3>How to create your own color palate?</h3><p>Warm colors represent passion and energy and cools colors represent calms and equality. Other colors represent emotions and behaviors. So, as discussed above color used expresses culture, life experience, gender and emotion.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=753141af4466" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TOP 15 Matplotlib and Seaborn Major Plots]]></title>
            <link>https://medium.com/@shovitkafle/top-15-matplotlib-and-seaborn-major-plots-d237481683cf?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/d237481683cf</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[eda]]></category>
            <category><![CDATA[seaborn]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[matplotlib]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Sun, 22 Jun 2025 23:08:23 GMT</pubDate>
            <atom:updated>2025-06-22T23:08:23.382Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Line Plot</h3><p>· <strong>Library</strong>: Matplotlib</p><p>· <strong>Code</strong>: plt.plot(x, y)</p><p>· <strong>Parameters</strong>:</p><p>o x, y: Data points</p><p>o label: Label for the line (used in legends)</p><p>o color: Color of the line</p><p>o linestyle: Style of the line (‘-’, ‘ — ‘, ‘:’, etc.)</p><p>o linewidth: Width of the line</p><p>o marker: Marker style (e.g., ‘o’, ‘x’)</p><p>· <strong>Explanation</strong>: Displays data as a continuous line.</p><p>· <strong>Example</strong>: plt.plot([1, 2, 3], [4, 5, 6], marker=’o’, color=’blue’)</p><p>· <strong>Usage</strong>: Trend analysis over time, stock prices, sensor data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*dbbMp2G53xxqEUjG.png" /><figcaption>Fig: Line Plot in Matplotlib</figcaption></figure><p>Seaborn also have lineplot but we prefer matplotlib.</p><h3>2. Bar Plot</h3><p>· <strong>Library</strong>: Matplotlib / Seaborn</p><p>· <strong>Code</strong>: plt.bar(x, height) / sns.barplot(x, y, data=df)</p><p>· <strong>Parameters</strong>:</p><p>o x, y: Data</p><p>o data: DataFrame for seaborn</p><p>o hue: Grouping variable</p><p>o palette: Color palette</p><p>o orient: ‘v’ or ‘h’ (vertical/horizontal)</p><p>· <strong>Explanation</strong>: Compares quantities across categories.</p><p>· <strong>Example</strong>: sns.barplot(x=’category’, y=’sales’, data=df)</p><p>· <strong>Usage</strong>: Sales comparison, categorical analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*vzsTbr6x56HeHwC0.png" /><figcaption>Fig: Bar Plot in Matplotlib</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*s2ZS_6_9WqCPTxGJ.png" /><figcaption>Fig: Barplot in Seaborn</figcaption></figure><h3>3. Histogram</h3><p>· <strong>Library</strong>: Matplotlib / Seaborn</p><p>· <strong>Code</strong>: plt.hist(data) / sns.histplot(data)</p><p>· <strong>Parameters</strong>:</p><p>o bins: Number of bins</p><p>o kde: (Seaborn) Show KDE line</p><p>o color, alpha: Color and transparency</p><p>· <strong>Explanation</strong>: Distribution of numerical data.</p><p>· <strong>Example</strong>: sns.histplot(df[‘age’], bins=10, kde=True)</p><p>· <strong>Usage</strong>: Age distribution, salary analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*Mplb2rA5UlcoWUFP.png" /><figcaption>Fig: Histogram Plot in Matplotlib</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*lV1S2G1MxQNnXs9Z.png" /><figcaption>Fig: Histogram Plot in Seaborn</figcaption></figure><h3>4. Box Plot</h3><p>· <strong>Library</strong>: Seaborn (preferred) / matplotlib</p><p>· <strong>Code</strong>: sns.boxplot(x, y, data=df)</p><p>· <strong>Parameters</strong>:</p><p>o x, y, data, hue, palette</p><p>· <strong>Explanation</strong>: Displays distribution with quartiles, detects outliers.</p><p>· <strong>Example</strong>: sns.boxplot(x=’gender’, y=’salary’, data=df)</p><p>· <strong>Usage</strong>: Outlier detection, spread visualization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*jiM6Zd2OK47XMh_j.png" /><figcaption>Fig: Box plot in seaborn</figcaption></figure><h3>5. Violin Plot</h3><ul><li><strong>Library</strong>: Seaborn</li><li><strong>Code</strong>: sns.violinplot(x, y, data=df)</li><li><strong>Parameters</strong>: Same as boxplot, with inner (e.g., ‘box’)</li><li><strong>Explanation</strong>: Combines boxplot and KDE.</li><li><strong>Example</strong>: sns.violinplot(x=’category’, y=’value’, data=df)</li><li><strong>Usage</strong>: Advanced distribution analysis.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*HKFuD87uRmzmwU_n.png" /><figcaption>Fig: Violin Plot in Seaborn</figcaption></figure><h3>6. Scatter Plot</h3><p>· <strong>Library</strong>: Matplotlib / Seaborn</p><p>· <strong>Code</strong>: plt.scatter(x, y) / sns.scatterplot(x, y, data=df)</p><p>· <strong>Parameters</strong>:</p><p>o x, y, hue, style, size, palette</p><p>· <strong>Explanation</strong>: Relationship between two continuous variables.</p><p>· <strong>Example</strong>: sns.scatterplot(x=’age’, y=’income’, data=df, hue=’gender’)</p><p>· <strong>Usage</strong>: Correlation, trend exploration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*vAjkgqpfp8GsDEnU.png" /><figcaption>Fig: Scatter Plot in Matplotlib</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*8CfrbgRzZNGmpveH.png" /><figcaption>Fig: Scatter Plot in Seaborn</figcaption></figure><h3>7. Pair Plot</h3><p>· <strong>Library</strong>: Seaborn</p><p>This is a high-level Seaborn function specifically designed to visualize pairwise relationships between multiple variables in a dataset. It generates a grid of subplots, and the type of plot in each subplot depends on its position in the grid.</p><p>· <strong>Code</strong>: sns.pairplot(data)</p><p>· <strong>Parameters</strong>:</p><p>o hue, palette, kind, diag_kind</p><p>· <strong>Explanation</strong>: All pairwise scatter plots for multiple variables.</p><p>· <strong>Example</strong>: sns.pairplot(df, hue=’target’)</p><p>· <strong>Usage</strong>: Exploratory data analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/0*oaNgrokZSDmfRg0F.png" /><figcaption>Fig: Pair Plot</figcaption></figure><h3>8. Heatmap</h3><p>· <strong>Library</strong>: Seaborn</p><p>· <strong>Code</strong>: sns.heatmap(data)</p><p>· <strong>Parameters</strong>:</p><p>o annot, cmap, linewidths, linecolor</p><p>· <strong>Explanation</strong>: Color-coded matrix representation.</p><p>· <strong>Example</strong>: sns.heatmap(df.corr(), annot=True, cmap=’coolwarm’)</p><p>· <strong>Usage</strong>: Correlation matrices, confusion matrices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/0*E5_Flp2a791R4Xvl.png" /><figcaption>Fig: Heatmap in Seaborn</figcaption></figure><h3>9. Count Plot</h3><p>· <strong>Library</strong>: Seaborn</p><p>· <strong>Code</strong>: sns.countplot(x, data=df)</p><p>· <strong>Parameters</strong>:</p><p>o x, hue, palette</p><p>· <strong>Explanation</strong>: Frequency of categorical values.</p><p>· <strong>Example</strong>: sns.countplot(x=’department’, data=df)</p><p>· <strong>Usage</strong>: Count of categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/0*UerGHrYmIgkXiGKp.png" /><figcaption>Fig: CountPlot in Seaborn</figcaption></figure><p>Barplot gives mean value while countplot gives the total counted value.</p><h3>10. Pie Chart</h3><p>· <strong>Library</strong>: Matplotlib</p><p>· <strong>Code</strong>: plt.pie(sizes)</p><p>· <strong>Parameters</strong>:</p><ul><li>labels, autopct, startangle, shadow, explode</li></ul><p>· <strong>Explanation</strong>: Proportional representation in circular format.</p><p>· <strong>Example</strong>: plt.pie([10, 30, 60], labels=[‘A’,’B’,’C’], autopct=’%1.1f%%’)</p><p>· <strong>Usage</strong>: Market share, budget allocation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*lQljCgvlL5Q0Tink.png" /><figcaption>Fig: PieChart</figcaption></figure><h3>11. KDE Plot</h3><p>· <strong>Library</strong>: Seaborn</p><p>· <strong>Code</strong>: sns.kdeplot(data)</p><p>· <strong>Parameters</strong>:</p><p>o shade, bw_adjust, cumulative</p><p>· <strong>Explanation</strong>: Smooth estimate of distribution.</p><p>· <strong>Example</strong>: sns.kdeplot(df[‘age’], shade=True)</p><p>· <strong>Usage</strong>: Alternative to histogram. KDE can produce a plot that is less cluttered and more interpretable</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*eYD6Rapow-xMJ7kd.png" /><figcaption>Fig: KDE Plot</figcaption></figure><h3>12. Strip Plot</h3><p>· <strong>Library</strong>: Seaborn</p><p>· <strong>Code</strong>: sns.stripplot(x, y, data=df)</p><p>· <strong>Parameters</strong>:</p><p>o jitter, hue, dodge</p><p>· <strong>Explanation</strong>: Scatter plot for categorical variable.</p><p>· <strong>Example</strong>: sns.stripplot(x=’gender’, y=’salary’, data=df)</p><p>· <strong>Usage</strong>: Distribution over category.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*wlB4to9QdtFsX4pV.jpeg" /><figcaption>Fig: Strip Plot in Seaborn</figcaption></figure><h3>13. Swarm Plot</h3><ul><li><strong>Library</strong>: Seaborn</li><li><strong>Code</strong>: sns.swarmplot(x, y, data=df)</li><li><strong>Parameters</strong>: Similar to stripplot but avoids overlap.</li><li><strong>Explanation</strong>: Enhanced scatter with non-overlapping points.</li><li><strong>Usage</strong>: Visualizing all data points with distribution.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*tP8U9ZvzXSXzNEUC.png" /><figcaption>Fig: Swarm plot in seaborn</figcaption></figure><h3>14. Joint Plot</h3><p>· <strong>Library</strong>: Seaborn</p><p>· <strong>Code</strong>: sns.jointplot(x, y, data=df)</p><p>· <strong>Parameters</strong>:</p><p>o kind: ‘scatter’, ‘kde’, ‘hex’, ‘reg’</p><p>· <strong>Explanation</strong>: Combines scatter plot and histograms.</p><p>· <strong>Usage</strong>: Relationship and distribution of two variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*KnXYwnnXGNe2hAdx.png" /><figcaption>Fig: Joint Plot in Seaborn</figcaption></figure><h3>15. Regression Plot</h3><p>· <strong>Library</strong>: Seaborn</p><p>· <strong>Code</strong>: sns.regplot(x, y, data=df)</p><p>· <strong>Parameters</strong>:</p><p>o scatter, line_kws, ci</p><p>· <strong>Explanation</strong>: Shows regression line with data.</p><p>· <strong>Example</strong>: sns.regplot(x=’age’, y=’income’, data=df)</p><p>· <strong>Usage</strong>: Trend + prediction fit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/0*hs1Ha0zgH4gDz6ez.png" /><figcaption>Fig: Regression Plot</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d237481683cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pandas Part 2]]></title>
            <link>https://medium.com/@shovitkafle/pandas-part-2-596eb2ecd0b6?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/596eb2ecd0b6</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[group-by]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Sun, 18 May 2025 13:14:36 GMT</pubDate>
            <atom:updated>2025-05-18T13:14:36.722Z</atom:updated>
            <content:encoded><![CDATA[<p>In part 2, we will discuss more on CSV Files:</p><h4>1. Explain all functions for CSV files.</h4><p>To read CSV:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*mG83eg-5eSTPPb5JXTOg4w.png" /></figure><p>CSV functions are:</p><ol><li>.index : This shows range of index (start, end, step)</li><li>.columns : All names of columns will be shown</li><li>.describe : It will show count, mean, min value, max value, etc that will describe the data</li><li>.head : First Five starting data if value inside head is not given.</li><li>.tail : Last Five ending data if value inside tail is not given.</li><li>[2] : indexing for data</li><li>.to_numpy : Convert the data into numpy array</li><li>.asarray(var_name) : By importing numpy, it converts the data of var in numpy array</li><li>.sort_index(axis = 0 or 1, ascending = True or False) : Used to sort dataframe by index labels, axis = 0 to sort rows by index and axis = 1 to sort columns by index</li><li>df.loc[‘row3’, ‘Score’] = 95 : To change values in csv files</li><li>df.loc[[‘row1’, ‘row2’], [‘columnA’, ‘columnB’]] : Access multiple rows and columns</li><li>df.loc[‘row1’, ‘columnA’] : Access specific rows and columns</li><li>.iloc : for position based index similar to loc</li><li>.drop(column name or row name, axis) : remove row and columns</li></ol><h4>2. Explain handling missing data (replace NaN).</h4><p>Ans: So, there is a function called dropna which will remove the entire row if there is any empty value. To remove the column axis = 1 args is provided. Parameters:</p><p>i. how=&quot;any&quot; : Drop rows where all values are NaN</p><p>ii. axis = 1 : Drop columns</p><p>iii. subset = [&#39;column1&#39;, ‘column2’] : Drop NaNs in specific columns only</p><p>iv. df.dropna(inplace=True) : Modify the original DataFrame</p><p>v. df.dropna(thresh=3) :keeps rows with at least 3 non-NaNs</p><p>And, there is another function called fillna which is used to fill the values if there are any empty values. But we must pass a parameter which should replace the NaN value. Parameters:</p><p>i. df.fillna(0) :Replace all NaNs with 0<br>df.fillna(‘Unknown’) :Replace NaNs in string columns</p><p>ii. df.fillna(method=’ffill’) :Fill NaNs with previous non-NaN<br>df.fillna(method=’bfill’) :Fill NaNs with next non-NaN</p><p>axis = 0 and 1 for row and column wise filling</p><p>iii. df.fillna({‘Age’: 30, ‘Salary’: 50000}) : Fill using a dictionary (column-wise).</p><p>iv. df.fillna(method=’ffill’, limit=1) : Limit the number of fills.</p><p>The inplace=True argument in pandas <strong>modifies the original DataFrame or Series directly</strong> instead of returning a new one. inplace=True <strong>does not change or overwrite the original CSV file</strong> — it only modifies the DataFrame in memory.</p><h4>3. Explain replace and interpolate functions.</h4><p>Ans: Replace function generally replaces the values. It’s arguments are:</p><p>toreplace=&#39;what to replace&#39;, value=&#39;with what?&#39;</p><p>[1,2,3,4,5], 10 -&gt; this replaces all those values in list with 10</p><p>&quot;[A-Za-z]&quot;, &quot;python&quot;, regex = True -&gt; replace all a to z with python</p><p>(value, ffill = True) -&gt; replaces data with forward data and for backward data bfill = True is done, you can use limit = n for how much data you want to replace.</p><p>inplace = True for original data.</p><p>Now, interpolate function takes a missing data and automatically fills it sequencially.</p><p>.interpolate() -&gt; fills missing data according to forward and backward data matching the numbers. It doesnot work for alphabets though. So the parameters used for this function are:</p><p>.method = &quot;linear&quot; -&gt; linearly fills the data where there is a parameter axis where 0 for columns 1 for rows , fills with data accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*F8sTBXWfwSLITOtWwG238g.png" /><figcaption>source: ChatGPT</figcaption></figure><h4>4. How to merge data frames?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*V3gERa_5BLj1ZTkP2n4REQ.png" /></figure><p>Ans: In the figure above, the common part is “A”, so when we merge it combines both variable and gives output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*q7nhP3vjwP7k3wxFoUBGgw.png" /></figure><p>But in this figure the common part of A is only 1,2,3 so it gives the part which is just common.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*IsODA1TtUd_vNhU4C16BSQ.png" /></figure><p>Similarly, for this, howargument gives the var1 dataframe as it is the left dataframe. So, it gives the merge value of left dataframe only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*2WztJYIuj3F4vX1YQnlgqg.png" /></figure><p>Similarly for this, how = outer returns <strong>all rows</strong> from both DataFrames, filling in NaN where data is missing on either side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*hf0nNM-RrvEZyvtF2icMNA.png" /><figcaption>Source: Chat GPT</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*FeR3_zVKlsVys6__RsplWw.png" /></figure><p>Merges two DataFrames on index, renaming overlapping columns using custom suffixes for clarity.</p><h4>5. How to concat data frames?</h4><p>Ans: It is used to <strong>glue DataFrames together</strong> along rows or columns.</p><p>axis = 0 for row and axis = 1 for column based concat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*4bIzrstxpLU0T2xCwlDGuQ.png" /></figure><p>join = inner for removing all missing data.</p><p>keys = [&#39;name1&#39;, &#39;name2&#39;] It gives the keys and value for merging data.</p><h4>6. Write about groupby function in Pandas?</h4><p>Ans: Imagine a dataframe like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*oaV0-LbdTtXLWZECgluAjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/1*HqVaXwJtpY5TzRulufwzQQ.png" /></figure><p>Then we use groupby function and pass the name of the column inside it as a parameter and it groups the data accordingly. But to access it we use a loop and see data accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*ByT4kM-h8tB8tO1hsqs06Q.png" /></figure><p>Then the output with for loop will be seperated a and all the groups of a, for b and then the group of b accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*IU7PC7QJvhMUVx7LukjhlA.png" /></figure><p>But to get the data of <strong>a </strong>only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*-J2iM69IBAYbw9lFM34NFA.png" /></figure><p>But to get the data of each name from the minimum value. .min()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*q8cII2w-_Cgsni_t0V643A.png" /></figure><p>Similarly for the maximum we use .max() function and for the mean we use .mean() function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=596eb2ecd0b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pandas in Python]]></title>
            <link>https://medium.com/@shovitkafle/pandas-in-python-2c7daff5821e?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c7daff5821e</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Sun, 27 Apr 2025 18:03:20 GMT</pubDate>
            <atom:updated>2025-04-27T18:03:54.124Z</atom:updated>
            <content:encoded><![CDATA[<h4>1. What is data analysis? What are python libraries for data analysis?</h4><p>Ans: Data analysis is a process of inspecting, cleansing, transforming, and modelling data with the goal of discovering useful information, informing conclusions, and supporting decision-making.</p><p>Python libraries:</p><ul><li><strong>Pandas</strong> — for data manipulation and analysis (working with tables, CSV files, etc.)</li><li><strong>NumPy</strong> — for numerical operations and handling arrays</li><li><strong>Matplotlib</strong> — for data visualization (basic graphs and plots)</li><li><strong>Seaborn</strong> — for more advanced and beautiful data visualizations</li><li><strong>SciPy</strong> — for scientific and technical computations</li><li><strong>Scikit-learn</strong> — for data modeling, machine learning, and predictive data analysis</li><li><strong>Statsmodels</strong> — for statistical modeling and hypothesis testing</li><li><strong>Plotly</strong> — for interactive data visualizations</li><li><strong>Openpyxl</strong> — for reading/writing Excel files</li><li><strong>SQLAlchemy</strong> — for working with databases</li></ul><h4>2. What is Pandas?</h4><p><strong>Ans: Pandas</strong> is a powerful <strong>Python library</strong> for <strong>working with structured data</strong> (like tables, spreadsheets, CSVs). It lets you <strong>load</strong>, <strong>clean</strong>, <strong>manipulate</strong>, <strong>analyze</strong>, and <strong>visualize</strong> data easily. The main building blocks in Pandas are:</p><ul><li><strong>DataFrame</strong> (like a whole Excel sheet — rows and columns)</li><li><strong>Series</strong> (like a single column)</li></ul><p>Start with</p><p>pip install pandas</p><p>Then in code we always begin with:</p><p>import pandas as pd</p><h4>3. Explain series in Pandas.</h4><p>Ans: It is a one dimensional array capable of holding data of various types. Emptiness in series is denoted by NaN</p><p>a = pd.Series()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*ProZz_OVeC-r_9UnCJXP3Q.png" /><figcaption>series representation in python</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*PCGoHLz0xPRsKy07ejhMRg.png" /><figcaption>more on series</figcaption></figure><h4>4. Explain DataFrame in Pandas.</h4><p>Ans: They are 2D data structures. A <strong>DataFrame</strong> is a <strong>table</strong> — <strong>rows and columns</strong>, just like an <strong>Excel sheet</strong> or <strong>SQL table</strong>. It is made up of <strong>multiple Series</strong> (columns). Each column can have different types of data (numbers, text, dates).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*1873USYTz0Bx-mN_eYsyMQ.png" /></figure><h4>5. Give some examples of arithmetic operations in Pandas.</h4><p>Ans:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*amO7vzyFyVvQQTilt3siSQ.png" /></figure><p>Similarly like addition in the above picture, we can do +, — ,*, %, /, etc.</p><p>Other arithmetic operation include:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*yBOTafqooOFNMHzHoKVrDg.png" /></figure><p>Similarly, you can perform other comparision operators too.</p><h4>6. How to delete and insert data in Pandas?</h4><p>Ans:</p><blockquote>Insert</blockquote><p>First lets begin with a dataframe. And then we use inssert operation provide the index and the values to insert.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*CQzqTYrntnMAxMQbZ1zGBw.png" /></figure><p>Another way of insertion is like this where it appends to the last and we can perform series slicing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*M3bIXW1S9VoxleT6pn6sbA.png" /></figure><blockquote>Delete: Use pop function</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*Yo7_MWDOdmPuFpD4UZSPfw.png" /></figure><p>Another method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*WyVrTwUwrMAoNxxK_Y0CBg.png" /></figure><h4>7. Explain about CSV file in Pandas.</h4><p>Ans: <strong>CSV</strong> stands for <strong>Comma-Separated Values</strong>. It’s a simple text file where <strong>each line is a row</strong> and <strong>columns are separated by commas</strong>. CSV files are mainly used for <strong>storing tabular data</strong> (like spreadsheets) in a <strong>lightweight</strong> and <strong>easy-to-read</strong> format.</p><p>To create a CSV File in Pandas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*OY2M3m_rJrXgIXhS8aIPrA.png" /></figure><h4>8. How to Read CSV files in Python?</h4><p>Ans:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQMKHG55QdHZRO2skTEtZw.png" /></figure><p>Also,</p><p>To just get the required data of row only: <em>nrows</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsRA4Z1_hcVW59FFc8diVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pSG_GpOb22VEQxUq3V-ttQ.png" /></figure><p>To get the required data of columns only: <em>usecols</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5oiHeabgq5HdoFdH8VUYQ.png" /></figure><p>To get the required data of multiple columns: <em>usecols</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kSnUOiWh8_nUsJ1DD-m4sg.png" /></figure><p>To use rows by skipping the required row: <em>skiprows</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCfjxWDFHH4W-9WKQj17dA.png" /><figcaption>before</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fbXjqPqTuPopzhLIaRR2Bw.png" /><figcaption>after</figcaption></figure><p>To make a column an index: <em>index_col</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YSJdp6IHfWx2ylNKyQPZiA.png" /></figure><p>To make a row header: <em>header</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UVTrFCnY2Mhtkzzw2oZYXA.png" /></figure><p>To make your own header: <em>names</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OuqAT6d02Nky_cs8_1-5Tg.png" /></figure><p>Remove the header: <em>header=None</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1jSmWpozfT0zloCI7rw4w.png" /></figure><p>We can use prefix to use col1, col2</p><p>To change the data type of a particular column:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JH77s3G2E9yvnELNm0FaLg.png" /></figure><p>For more my pandas part 2 series will come.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c7daff5821e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django]]></title>
            <link>https://medium.com/@shovitkafle/django-d5bf178b2368?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5bf178b2368</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 09:34:58 GMT</pubDate>
            <atom:updated>2025-03-17T09:34:58.292Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django — Part 2</h3><p>In this module, I found it challenging to explain everything in the code thoroughly. However, I utilized ChatGPT-generated code to present the concepts in a more systematic and easy-to-understand manner, making the learning process smoother and more effective.</p><h3><strong>Extends and include In Django</strong></h3><p>Include is for including the part of Django which we did in previous parts. The {% extends %} tag in Django is used for <strong>template inheritance</strong>, allowing child templates to extend a base (parent) template. This helps in maintaining a consistent layout across multiple pages while modifying only specific sections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*YXZSXc_D6Y60n-f7BAP5zQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*zqdBWYHXA7Zq_uZVOcrlvQ.png" /></figure><h3><strong>What are URL Template tags?</strong></h3><p>In Urls.py what path we give, we can give the same name in our href tag of HTML to link the pages. For like: about-us/ in urls.py and html href tag.</p><p>The name we pass is used for URL tag. Directly in href tag we can give <strong>{%url ‘name’%}</strong></p><h3><strong>How to highlight link in Django?</strong></h3><p>When building a Django website, you might want to <strong>highlight the currently active link</strong> in your navigation bar. This helps users see which page they are on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*bFbhQb_EZFncZcsVWP0tmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*F_8dlt03swMTEZsUJAiVkA.png" /></figure><h3><strong>What are HTTP request in Python (GET and Post)? (Django Tutorial)</strong></h3><p>To get a value from form, we need to clear about HTTP request. In Django, views handle HTTP requests using different <strong>HTTP methods</strong>. The two most common methods are:</p><p>1. <strong>GET Method</strong>: Used to <strong>request data</strong> from the server.</p><p>2. <strong>POST Method</strong>: Used to send <strong>data to the server</strong> (e.g., form submissions)</p><h4>Get Method:</h4><p>· <strong>The GET method</strong> sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character.</p><p>· <a href="https://www.wscubetech.com/index.php?name1=value1&amp;name2=value2">https://www.wscubetech.com/index.php?name1=value1&amp;name2=value2</a></p><p>· Restricted to send up to <strong>1024 characters only</strong>.</p><p>· <strong>Never use GET method</strong> if you have <strong>password</strong> or other <strong>sensitive information</strong>.</p><p>· <strong>Cannot be used</strong> to send <strong>binary data</strong>, like images or word documents, to the server.</p><h4>Post Method:</h4><p>· <strong>The POST method</strong> transfers information via <strong>HTTP headers</strong>. The information is encoded as described in the case of <strong>GET method</strong> and put into a header called <strong>QUERY_STRING</strong>.</p><p>· <strong>Does not have any restriction</strong> on data size to be sent.</p><p>· <strong>Can be used</strong> to send <strong>ASCII as well as binary data</strong>.</p><p>· The data sent by the <strong>POST method</strong> goes through the <strong>HTTP header</strong>, so <strong>security depends on the HTTP protocol</strong>.</p><p>· <strong>By using Secure HTTP</strong>, you can make sure that your <strong>information is secure</strong>.</p><h3><strong>Implementation of GET method:</strong></h3><p>We make a form in HTML and we give the name to the value we need from the form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*_UdfwWFcLTa0DJausRADag.png" /></figure><h3><strong>Implementation of POST Method: (CSRF Token)</strong></h3><p>When a form is submitted in Django, it ensures the data is coming from the correct source by checking the CSRF token. This token helps protect against Cross-Site Request Forgery (CSRF) attacks by verifying that the request is made by the user and not from an external malicious site.</p><p>In HTML file above the form: {% csrf_token %}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*feTBRo_cL6hbZ6jjWwHL2A.png" /></figure><p>To make the data still be there:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*To9NleAF0UdpM7EVrG2qSA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*S4bxIK0UdJZFkc1ZEBL68w.png" /></figure><h3><strong>What is Redirect and How to Redirect Page in Django?</strong></h3><p>A <strong>redirect</strong> in web development refers to the process of forwarding a user from one URL to another. In Django, this is typically done after a successful form submission, where you want to send the user to a confirmation page, or after performing some action, such as logging in or logging out.</p><pre>from django.shortcuts import redirect<br>def my_view(request):<br># Redirect to a different view or URL<br>return redirect(&#39;/some-url/&#39;)</pre><p>or,</p><pre>from django.shortcuts import redirect<br>from django.http import HttpResponseRedirect<br>def form_view(request):<br>if request.method == &quot;POST&quot;:<br># Process form data here<br>return redirect(&#39;success_page&#39;)<br>return render(request, &#39;form_template.html&#39;)</pre><h3><strong>What is HTML Action URL in Django?</strong></h3><p>In Django, the <strong>HTML action URL</strong> is used in forms to specify where the form data should be sent upon submission. It is defined using the action attribute inside the &lt;form&gt; tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*wMyCqqhBHgx1CMtwia9KEQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*n1AIM1f_ml1ZF9p-N0hXmg.png" /></figure><h3><strong>Form Tutorial in Django</strong></h3><p>1. Make a file named forms.py</p><p>2. From Django import forms</p><p>3. Create a class named userForms(forms.Form):</p><p>4. In views.py do from .forms import usersForms</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*qMQADbjtRUbFm0fv9IxhDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*bKAn0wTyRWqvmBnjN0MiKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*H-QDkvsbwvtXI34bniYw-A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5bf178b2368" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DJANGO — Python(Part 1)]]></title>
            <link>https://medium.com/@shovitkafle/django-python-part-1-7735b2b63237?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/7735b2b63237</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Thu, 13 Mar 2025 16:52:51 GMT</pubDate>
            <atom:updated>2025-03-13T16:52:51.868Z</atom:updated>
            <content:encoded><![CDATA[<h3>DJANGO — Python(Part 1)</h3><p>Django is the most popular Python framework used to create web applications. To install Django, use the following command:</p><p>```<br>pip install Django<br>```</p><p>Django can be used to build a wide range of websites, from content management systems to social networks and news sites. It works with any client-side framework and delivers content in various formats like HTML, RSS, JSON, and XML.</p><p>Django follows the MVT (Model-View-Template) architecture, a software design pattern with three key components:</p><ol><li><strong>Model</strong>: Handles the data interface, representing the structure and relationships of your data.</li><li><strong>View</strong>: Manages the user interface logic, processing user requests and determining what to display.</li><li><strong>Template</strong>: Contains the static HTML structure and defines how dynamic content is inserted into the page.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*ztWDbxEBgH-tKM_p7RofZQ.png" /></figure><p>For better understanding, in a food order system using Django’s MVT architecture, the <strong>Model</strong> defines the data, such as food items and customer orders. The <strong>View</strong> handles the logic, processing requests like displaying the menu or placing an order, by retrieving data from the model. The <strong>Template</strong> is responsible for presenting the data to the user, such as showing the food items and their prices in an HTML format. Together, they work to manage data, process user actions, and display content in a dynamic and structured way.</p><h4>1. Starting a New Project:</h4><p>So, before starting a new project, we need to know all the subcommands of Django. To know it, we go to the command prompt and write:</p><p>django-admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qCsoMJ1XYBYHg11Bq3FIrQ.png" /></figure><p>Then, It shows all the commands we can do via django-admin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*OaTQ2owEi29qzEBt5gUwtg.png" /></figure><p>Now, lets start learning by knowing the usage of everything. So, to start with, lets create a folder and open the folder location in command prompt. Inside the command prompt, you then start by writing:</p><p>django-admin startproject PROJECTNAME</p><p>Then, it creates some python files inside the folder, which is the starting of our project. But, we need to know about all those python files and their use cases.</p><p>In the terminal you type this, This starts your project.</p><p>Python manage.py runserver</p><p>In terminal you write this line, this runs the development server:</p><p>1. It initializes a port in 8000 default server.</p><p>2. Sometimes, 8000 port might overlap when we make a website in angular and Django (a reference), to avoid this collapse you can write:<br> python manage.py runserver 4444</p><p>Here, 4444 is the new port for your project</p><p>3. Ctrl + C to stop your server</p><h3><strong>Folder Structure of Django:</strong></h3><p>- A default SQLite data base is created in your Django project which we can check through DB browser.</p><p>- We have to create a new folder name templates: <strong>HTML files</strong></p><p>- We have to create a new folder name static: <strong>CSS, JS, Fonts files</strong></p><p>- We have to create a new folder name media (for dynamic files): <strong>Changing images </strong><em>(Example: Add a product to your ecommerce page)</em></p><p>- A folder named by your project is default that contains:</p><h4>Settings.py file:</h4><p>· It has imported path that has your base directory path. There is a secret key which is made default. Debug = True to know the errors.</p><p>· Allowed_Hosts = []: contains all your hosts.</p><p>· Installed_apps = Default tables</p><p>· Middleware = Restriction (For example: security like show dashboard only when user logins)</p><p>· Templates = ‘Dirs’:[BASE_DIR, “template folder”]</p><p>· Database = Default sqlite, change engine and name to change the database</p><p>· Auth_password_validate for login system.</p><p><strong>Uses of settings.py:</strong></p><p>1. For database</p><p>2. For url of templates</p><p>3. For url of static, templates and media</p><h4>Urls.py: Create url for your all works.</h4><h4>Manage.py: To run project (does not contain much changes in code)</h4><h3>Default Migrations in Django:</h3><p>When we create a model in Django (Database Table means model for like CRUD operations). When we migrate the model, the tables are created in databases. For admin panel, we need to create admin and perform migration. For that, we can create a <strong>Superuser</strong>.</p><p>Python manage.py makemigrations : When we create a new database model, we use to create this. But to update the database: we run</p><p>python manage.py migrate</p><p>But in default, migrations are already made in sqlite database, so to do it, we do python manage.py migrate. Now to check whether the tables are migrated or not, we can check your database via <strong>DB browser.</strong></p><h3>Create superuser in Django:</h3><p>To create it we have a command: python manage.py createsuperuser, then we fill all those email, username, password, etc. Then we can see the DB browser, the user is updated in it.</p><p>To verify that, go to localhost:8000/admin/ and give the username and password.</p><p>Then we can access the admin. But in default it gives, group and users, for more function we have to create modules inside admin, there will be an option for administrator. This clears there are two parts of website, one for the admin (superuser) and another for the client.</p><h3>URLs and Views in Django:</h3><p>Urls are like routes: for like /admin, /about-us/location. This // representations are slug or routings. This can directly open the inside page of the website, by accessing through the slug.</p><p>Views are the logic that client see (works on HTTP method) that works from the URL. One view is connected to one URL. Views are rendering of the URL on the HTML page.</p><p>There are two files: urls.py to define all url and views.py to define all views. Views are either function or class logic. They are connected. To change the path:</p><p>The change is admin-panel from admin.</p><h4>How to create your own URLs and views and connect them:</h4><p>Inside your project, you create a views.py file where we import http response file:</p><p><strong>from Django.http import HttpResponse</strong> : This will work to give response to the browser.</p><p>Then create function and objects, e.g.: create like this.</p><p>def aboutUs(request):</p><p>return HTTPresponse(“HELLO WORLD”)<strong> in actual process we render HTML</strong></p><h4>Now in urls.py:</h4><p>From projectname import views</p><p>urlpattern = [path(‘about-us/’, views.aboutUS)</p><p>This is how they are connected.</p><p>Finally, done with the day one.</p><h3>Dynamic URLS and routes:</h3><p>Imagine a website with a lot of blogs, but when we click a blog, the details opens for the particular blog selected and it will be different for different blog even though it is in same path. But it has changed the url of the page, that url is termed as dynamic routes. Routes can be made on the basis of int, str or slug.</p><p>path(‘contactus/&lt;slug:s&gt;/’, contactUS) <strong>In urls.py</strong></p><p>def contactUS(request, s):</p><p>return HttpResponse(“Contact Us Page with slug: “ + s) <strong>In views.py</strong></p><h4><strong>How to render HTML Templates?</strong></h4><p>· In templates file, put your html file.</p><p>· In settings.py, go to the templates variable, and write BASE_DIR, “htmlfilepath” on the path key.</p><p>· In views.py file, from Django.shortcuts import render from Django, and then create a function that contains your HTML file.</p><p>· In urls.py connect the view with a path.</p><p>The difference between render and response is that, render can call your page even when its dynamic but response cannot call your page.</p><p><strong><em>Passing data from Django View to Template: provide data to html file from views.py</em></strong></p><p><strong>Using For Loop in Template:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*SgzIOxTevmy8UdzajBDKmQ.png" /><figcaption>in python</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*fek2STdB2UzDb4HJmL2EdQ.png" /><figcaption>in html</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/142/1*OvfRCSkGLc1XlyDuXw6yNg.png" /><figcaption>result</figcaption></figure><h4><strong>IF else statement:</strong></h4><p>It is same as we did for for loop just to end it we use endif inside the percentage bracket.</p><h4><strong>Managing Static File in Django (CSS and JS files):</strong></h4><p>1. Create a static folder where all files are there.</p><p>2. in settings.py file</p><pre>STATICFILES_DIRS = [<br>BASE_DIR, &quot;static&quot;] </pre><p>3. Connect the HTML files and CSS files</p><p>4. Another way if need in HTML file</p><pre>{% load static %}<br>&lt;link rel=&quot;stylesheet&quot; href=&quot;{% static &#39;polls/style.css&#39; %}&quot;&gt;</pre><h4><strong>Header Footer Part through Django (include tag in Django)</strong></h4><p>As header and footer are present in all the section of the page, we can put them in a folder and include all them in pages through Django. For that, we can do it by this method:</p><p>1. Make header and footer in different file</p><p>2. Put {% include “header.html” %}</p><p>All we did is put it in another file, and included in the required files.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7735b2b63237" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlock the Power of Fonts for Stunning UI Design]]></title>
            <link>https://medium.com/@shovitkafle/unlock-the-power-of-fonts-for-stunning-ui-design-a8db2b814dfe?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8db2b814dfe</guid>
            <category><![CDATA[ui-ux-design]]></category>
            <category><![CDATA[typography]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Sun, 19 Jan 2025 03:55:34 GMT</pubDate>
            <atom:updated>2025-01-19T03:55:34.276Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*Wz7_VITvKug-Dzoi40OijA.png" /></figure><p>Always, a question arises while doing work, whether it is in UI/UX design or video/photo editing work. The question that arises is selecting a font. Simply, font is a way in which a text is written. The word ‘a’ can be written in many fonts, whether it can be ‘Segoe UI’, ‘Times New Roman’, ‘Apstos Body’, etc. The major point here is all the a I wrote were different and it goes for all characters too. The agenda is there must be a way of choosing a font. We cannot use any sort of font anywhere, we have to choose it in such a way that it would attract people, it will make concise reading and they won’t have to pinch their eyes to read it. It comes with the principle of choosing a proper font, choosing its proper size, and choosing its proper decoration. Even the decoration of font is used for several cases, we cannot directly add underline in every text possible. We cannot write our whole essay in italics. So, there are certain rules for that.</p><p>For professional writing, we use bold text to highlight a section. In a resume, we write our name in bold decoration. We also use boldness to write about bold accomplishments in longer description paragraphs. The boldness determines the emphasis of the text.</p><p>Similarly, we write italic text for the name of a certain valuable thing, whether it be a book or a movie. Also, when we are including a word from another language. For example, <em>déjà vu</em>. It is mainly used while using referenced text in your paragraphs. And when we want to draw attention to a particular part, we use underline. For web developers, they use it to connect to a hyperlink. It is also used for visual separations in documents. For example, “Chapter 1- Typography”, etc.</p><p>Now, for a graphic designer, there comes a major part, which is selecting a font. The topic <strong>— Typography</strong>. “<em>Typography, the art of arranging text, plays a crucial role in making written language not only legible and readable but also emotionally engaging and appropriate for content. It is a fundamental element in graphic design, holding a central position in visual communication across various mediums, ranging from print to digital displays. — </em><strong><em>(Jin Choi, 2024). </em></strong>So, I would want people to <strong>Stop Guessing Fonts For your Designs.</strong> Most designers, tend to scroll the font without knowing what makes a decent font. So, we need to learn a better anatomy to make a better decision.</p><h4>Anatomy of a Font</h4><p>For a font, there is a baseline, it is an invisible line where our font sits. It provides plenty of structures, especially when we look at line height which is a space between consecutive baseline and the descender height is the portion of the letter that extends below the baseline. If we consider a font to be a box, then the height gap is its margin. The descender height is the most crucial part of UI that maintains readability and visual balance in text heavy layout. Also, there is a loop which is a enclosed counter of a lower case letter like ‘g’ , ‘y’, ‘p’ or ‘q’. It is modified so that it will help to gain a spicy character. While descender improve readability, the stem of a font is the core structure of any letter. Also, <strong>Serif font </strong>is for the shoes and hats that extend to a letter. Inside the letter, we have counters and open counters which are crucial for the legibility of small text sizes. Horizontal stroke provides legibility for fonts like t. X-height defines lowercase letter height, while ascender height extends above it, which is crucial for balance in UI text. Now, the space between each letter is called kerning, and each gap in kerning is unique. When we emulate a font picker, we can see there’s a visual difference in typefaces. All of them differ due to their anatomy. If you run a micro test on your typefaces, we can know the difference between baseline and descender height. Also, it will be more valuable running the kerning text, which will help you for the UI. I really hope it helps for selecting your font.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8db2b814dfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[This is what you must know about DECORATORS in Python (PART 1)]]></title>
            <link>https://medium.com/@shovitkafle/this-is-what-you-must-know-about-decorators-in-python-part-1-b9a9ee516824?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9a9ee516824</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[advanced]]></category>
            <category><![CDATA[decorators]]></category>
            <category><![CDATA[sad]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Mon, 13 Jan 2025 14:58:13 GMT</pubDate>
            <atom:updated>2025-01-13T14:58:13.604Z</atom:updated>
            <content:encoded><![CDATA[<h4>So, before beginning what are decorators?</h4><p>Decorator is a function that takes other function as argument and adds some kind of functionality and returns another function without altering the source code of original function. They allow you to wrap a function in another function, thus modifying its behavior. It is mainly used for code reusability.</p><p>To understand better, lets break down a code:</p><pre>def decorator_func(original_func):<br>    def wrapper_func():<br>        print(&quot;This was executed before display function by wrapper&quot;)<br>        return original_func()<br>    return wrapper_func<br><br>def display():<br>    print(&quot;THIS RAN DISPLAY FUNCTION&quot;)<br><br>decorator_display = decorator_func(display) #index: line no 8 for below explanation<br>decorator_display()</pre><blockquote>In this code, decorator_func(original_func) is a decorator function that takes original_func (in this case, display) as an argument. Inside decorator_func, a function wrapper_func is defined to &quot;wrap&quot; the original_func. The wrapper_func adds behavior (it prints a message) before calling and returning the result of original_func().</blockquote><blockquote>In line 8, when decorator_func(display) is called, it returns wrapper_func, which now wraps the display function. The decorator_display variable points to this wrapped version. When decorator_display() is called, it first prints the message from wrapper_func and then calls display().</blockquote><h4>Now a simpler and effective way to do is by using the function decorators method:</h4><pre>def decorator_func(original_func):<br>    def wrapper_func():<br>        print(&quot;This was executed before display function by wrapper&quot;)<br>        return original_func()<br>    return wrapper_func<br><br>@decorator_func<br>def display():<br>    print(&quot;THIS RAN DISPLAY FUNCTION&quot;)<br><br>display()</pre><blockquote>By using the decorator, <strong>decorator_display = decorator_func(display)</strong>. This line of code is simplified. So, it simply extended the behaviour of other function.</blockquote><p><strong>This is what functions do simply. There are some in-built decorators in Python too. We will discuss about them in this documentation:</strong></p><ol><li>staticmethod: When we need some functionality not w.r.t an Object but w.r.t the complete class, we make a method static. This method can’t access or modify the class state. This is used when we donot need any instance from the class.</li></ol><p>Without using static method:</p><pre>class Math:<br>    def add(self,a , b):<br>        return a + b<br><br>maths = Math()<br>print(maths.add(5,10)) #15</pre><p>By using static method:</p><pre>class Math:<br>    @staticmethod<br>    def add(a, b):<br>        return a + b<br><br>print(Math.add(5, 10))</pre><p>2. classmethod: It transforms a method into a class method. Here, it takes class (cls) as its first argument. A <strong>class method</strong> in Python is a method that is bound to the class rather than the instance of the class. Also, Class methods are bound to the class and not to an instance of the class.</p><pre>class MyClass:<br>    class_variable = 0  # Class-level attribute<br><br>    def __init__(self, instance_variable):<br>        self.instance_variable = instance_variable  # Instance-level attribute<br><br>    @classmethod<br>    def class_method(cls):<br>        print(f&quot;This is a class method. Class variable: {cls.class_variable}&quot;)<br><br>    @classmethod<br>    def change_class_variable(cls, value):<br>        cls.class_variable = value  # Modify class-level attribute<br><br><br># Create an instance<br>obj = MyClass(10)<br><br># Call class method via class or instance<br>MyClass.class_method()  # Output: This is a class method. Class variable: 0<br>obj.class_method()      # Output: This is a class method. Class variable: 0<br><br># Modify class variable using class method<br>MyClass.change_class_variable(100)<br>MyClass.class_method()  # Output: This is a class method. Class variable: 100</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9a9ee516824" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Sort and Shell Sort | Sorting (PART 2)| DSA Python | Module 6]]></title>
            <link>https://medium.com/@shovitkafle/quick-sort-and-shell-sort-sorting-part-2-dsa-python-module-6-063b69be3d42?source=rss-79ca39c3a734------2</link>
            <guid isPermaLink="false">https://medium.com/p/063b69be3d42</guid>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Shovit Kafle]]></dc:creator>
            <pubDate>Tue, 24 Dec 2024 12:26:27 GMT</pubDate>
            <atom:updated>2024-12-24T12:26:27.894Z</atom:updated>
            <content:encoded><![CDATA[<p>In previous blog, as we have discussed about 4 types of sorting. So, in this blog we will learn:</p><h3>5. Quick Sort</h3><p>It is simply a partition technique in python where a pivot element (either the starting one or middle one). So we put pivot in its correct position, which is called partitioning. There are two ways for it:</p><p>i. Hoare partition: The Hoare Partition scheme, developed by the British computer scientist C.A.R.<strong> </strong>Hoare, uses the leftmost element as the pivot. The partitioning process involves two pointers: the start pointer and the end pointer. The start pointer begins just before the pivot and moves to the right, looking for elements greater than or equal to the pivot. Meanwhile, the end pointer starts from the rightmost end of the array and moves left, searching for elements less than or equal to the pivot. Once both pointers have found the appropriate elements, they are swapped. This process continues until the pointers cross each other. At this point, the pivot is in its correct position, and the array is partitioned into two parts: elements smaller than the pivot are on one side, and elements larger than the pivot are on the other side. This method is more efficient than other partitioning schemes because it typically requires fewer swaps and ensures the pivot is correctly placed without necessarily splitting the array into two equal halves.</p><pre>def hoare_partition(arr, low, high):<br>    pivot = arr[low]<br>    i = low - 1<br>    j = high + 1<br>    <br>    while True:<br>        # Move i to the right until we find an element greater than or equal to pivot<br>        i += 1<br>        while arr[i] &lt; pivot:<br>            i += 1<br>        <br>        # Move j to the left until we find an element less than or equal to pivot<br>        j -= 1<br>        while arr[j] &gt; pivot:<br>            j -= 1<br>        <br>        # If the pointers have crossed, return j<br>        if i &gt;= j:<br>            return j<br>        <br>        # Swap elements at i and j<br>        arr[i], arr[j] = arr[j], arr[i]</pre><p>ii. Lomuto partition: The <strong>Lomuto Partition</strong> scheme is a simpler method of partitioning an array, commonly used in Quick Sort. In this approach, the pivot is typically chosen as the <strong>last element</strong> of the array. The algorithm uses a single pointer, called the <strong>partition index</strong>, to track the boundary between elements smaller than the pivot and those greater than or equal to it. Initially, the partition index is set just before the first element. The algorithm then scans through the array, and for each element smaller than or equal to the pivot, the partition index is incremented, and the element is swapped with the element at the partition index. Once the entire array is scanned, the pivot is swapped with the element at the partition index, placing the pivot in its correct position. This divides the array into two parts: elements smaller than the pivot on the left and elements greater than the pivot on the right. The Lomuto Partition is simpler to implement than Hoare’s Partition but can be less efficient, especially for large arrays or arrays with many duplicate elements, because it tends to require more swaps.</p><pre>def lomuto_partition(arr, low, high):<br>    pivot = arr[high]<br>    i = low - 1  # Pointer for smaller elements<br>    <br>    for j in range(low, high):<br>        if arr[j] &lt;= pivot:<br>            i += 1<br>            arr[i], arr[j] = arr[j], arr[i]  # Swap smaller element to the left side<br>    <br>    arr[i + 1], arr[high] = arr[high], arr[i + 1]  # Move pivot to its correct position<br>    return i + 1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IRBqmJ90anwwdMGo.png" /><figcaption>simple representation of quick sort</figcaption></figure><h3>Code For Quick Sort:</h3><pre># Partition function<br>def partition(arr, low, high):<br>    <br>    # Choose the pivot<br>    pivot = arr[high]<br>    <br>    # Index of smaller element and indicates <br>    # the right position of pivot found so far<br>    i = low - 1<br>    <br>    # Traverse arr[low..high] and move all smaller<br>    # elements to the left side. Elements from low to <br>    # i are smaller after every iteration<br>    for j in range(low, high):<br>        if arr[j] &lt; pivot:<br>            i += 1<br>            swap(arr, i, j)<br>    <br>    # Move pivot after smaller elements and<br>    # return its position<br>    swap(arr, i + 1, high)<br>    return i + 1<br><br># Swap function<br>def swap(arr, i, j):<br>    arr[i], arr[j] = arr[j], arr[i]<br><br># The QuickSort function implementation<br>def quickSort(arr, low, high):<br>    if low &lt; high:<br>        <br>        # pi is the partition return index of pivot<br>        pi = partition(arr, low, high)<br>        <br>        # Recursion calls for smaller elements<br>        # and greater or equals elements<br>        quickSort(arr, low, pi - 1)<br>        quickSort(arr, pi + 1, high)<br><br># Main driver code<br>if __name__ == &quot;__main__&quot;:<br>    arr = [10, 7, 8, 9, 1, 5]<br>    n = len(arr)<br><br>    quickSort(arr, 0, n - 1)<br>    <br>    for val in arr:<br>        print(val, end=&quot; &quot;) </pre><blockquote><strong>Another method of sorting is Heap Sort, which we wont include much :</strong></blockquote><blockquote>It is a comparison-based sorting algorithm that uses a binary heap data structure. It is an efficient algorithm with a time complexity of O(nlog⁡n)O(n \log n)O(nlogn) for both the worst and average cases. It is not preferred as it has <strong>Poor Cache Performance and Lack of Stability.</strong></blockquote><pre>def heapify(arr, n, i):<br>    largest = i  # Initialize largest as root<br>    left = 2 * i + 1  # Left child index<br>    right = 2 * i + 2  # Right child index<br>    <br>    # If left child is larger than root<br>    if left &lt; n and arr[left] &gt; arr[largest]:<br>        largest = left<br>    <br>    # If right child is larger than largest so far<br>    if right &lt; n and arr[right] &gt; arr[largest]:<br>        largest = right<br>    <br>    # If largest is not root, swap and continue heapifying<br>    if largest != i:<br>        arr[i], arr[largest] = arr[largest], arr[i]  # Swap<br>        <br>        # Recursively heapify the affected subtree<br>        heapify(arr, n, largest)<br><br>def heap_sort(arr):<br>    n = len(arr)<br>    <br>    # Build a max-heap (rearrange the array)<br>    for i in range(n // 2 - 1, -1, -1):<br>        heapify(arr, n, i)<br>    <br>    # One by one extract elements from the heap<br>    for i in range(n-1, 0, -1):<br>        # Move the current root (largest) to the end<br>        arr[i], arr[0] = arr[0], arr[i]<br>        <br>        # Call heapify on the reduced heap<br>        heapify(arr, i, 0)<br><br># Example usage:<br>arr = [12, 11, 13, 5, 6, 7]<br>heap_sort(arr)<br>print(&quot;Sorted array:&quot;, arr)</pre><h3>6. Shell Sort:</h3><p>Shell sort is a customization over insertion sort. Insertion sort requires many swaps and comparisons if heavy elements are located towards the end of an array. Shell sort will initially sort subarrays that are equal distance apart. The distance here is referred to as a gap. We will than keep on reducing the gap until it is 1. With gap=1 it becomes insertion sort but this time due to optimization we have performed earlier, sorting the array would require very less comparisons and element swaps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/0*daBOEpatI5IAfeUn.png" /></figure><pre>def shell_sort(arr):<br>    size = len(arr)<br>    gap = size//2<br><br>    while gap &gt; 0:<br>        for i in range(gap,size):<br>            anchor = arr[i]<br>            j = i<br>            while j&gt;=gap and arr[j-gap]&gt;anchor:<br>                arr[j] = arr[j-gap]<br>                j -= gap<br>            arr[j] = anchor<br>        gap = gap // 2</pre><blockquote>This overall ends the chapter of DSA.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=063b69be3d42" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>