Programming Articles

Page 60 of 2547

Generate Captcha using Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 27-Mar-2026 2K+ Views

A modified version of the PIL called Pillow library can be used to generate a text−based CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) in Python. Types of CAPTCHA There are different types of CAPTCHA and some of them are as follows ? Text−based CAPTCHA − A sequence of characters is provided with features distorted and random noise to make character recognition difficult. ...

Read More

Find the most Similar Sentence in the file to the Input Sentence | NLP

Jaisshree
Jaisshree
Updated on 27-Mar-2026 691 Views

Natural Language Processing (NLP) allows computers to interpret and analyze human language. Finding the most similar sentence to a given input is a common NLP task. Python provides several methods to accomplish this using libraries like NLTK and scikit-learn. Installation Requirements First, install the required libraries ? pip install nltk scikit-learn Algorithm Overview The sentence similarity algorithm follows these steps: Step 1: Load sentences from a text file Step 2: Preprocess both input sentence and file sentences Step 3: Tokenize sentences into individual words Step 4: Remove stop words to focus on ...

Read More

Python program to test for Non-neighbours in List

Mrudgandha Kulkarni
Mrudgandha Kulkarni
Updated on 27-Mar-2026 285 Views

When working with lists in Python, it can be valuable to identify non-neighbors, which are elements that are not adjacent to each other. Whether it's finding elements that are at least a certain distance apart or identifying gaps in a sequence, the ability to test for non-neighbors can provide valuable insights and facilitate specific operations. In this article, we will explore a Python program that tests for non-neighbors in a list. We will discuss the importance of identifying non-neighbors in various scenarios and provide a step-by-step explanation of the approach and algorithm used. Understanding the Problem Before ...

Read More

Python Program to swap two numbers without using third variable

Mrudgandha Kulkarni
Mrudgandha Kulkarni
Updated on 27-Mar-2026 861 Views

Swapping the values of two variables is a common operation in programming. Typically, the swap is performed using a third variable to temporarily store one of the values. However, there are several clever techniques to swap two numbers without using an additional variable, which can be useful for memory optimization or in constrained environments. In this article, we will explore different Python approaches to swap two numbers without using a third variable, including arithmetic operations and bitwise XOR operations. Method 1: Using Arithmetic Operations (Addition and Subtraction) This method uses basic arithmetic to swap values ? ...

Read More

Python Program to swap the First and the Last Character of a string

Mrudgandha Kulkarni
Mrudgandha Kulkarni
Updated on 27-Mar-2026 3K+ Views

In this article, we will explore a Python program to swap the first and last character of a string. Swapping characters within a string can be a useful operation in various scenarios, such as data manipulation, text processing, or even string encryption. We will discuss different approaches to solve this problem efficiently using Python, provide step-by-step implementations, and include test cases to validate the program's functionality. Understanding the Problem Before we dive into solving the problem, let's define the requirements and constraints more explicitly. Problem Statement − We need to write a Python program that swaps ...

Read More

Filtering a PySpark dataframe using isin by Exclusion

Jaisshree
Jaisshree
Updated on 27-Mar-2026 2K+ Views

PySpark DataFrames are distributed collections of data organized into named columns, similar to tables in a database. When working with large datasets, you often need to filter out specific rows based on whether column values match a predefined list. The isin() function combined with the negation operator (~) provides an efficient way to exclude rows by filtering out unwanted values. Understanding isin() Function The isin() function checks whether DataFrame values are present in a list of values. It returns a boolean result − True if the column value exists in the provided list, False otherwise. Syntax ...

Read More

Python program to Swap Keys and Values in Dictionary

Mrudgandha Kulkarni
Mrudgandha Kulkarni
Updated on 27-Mar-2026 6K+ Views

Dictionaries are a fundamental data structure in Python, providing a way to store key-value pairs. Sometimes you need to reverse the roles of keys and values in a dictionary. This operation is useful for data restructuring, creating value-based lookups, or removing duplicates. In this article, we will explore different methods to swap keys and values in a Python dictionary with practical examples. Understanding the Problem Swapping keys and values in a dictionary means creating a new dictionary where the original values become keys and the original keys become values. This is useful in scenarios such as: ...

Read More

Filter Pandas DataFrame Based on Index

Jaisshree
Jaisshree
Updated on 27-Mar-2026 672 Views

Pandas DataFrame filtering based on index is a fundamental operation for data analysis. The filter() method and boolean indexing provide flexible ways to select specific rows and columns based on their index labels. Syntax df.filter(items=None, like=None, regex=None, axis=None) Parameters items: List of labels to keep. Returns only rows/columns with matching names. like: String pattern. Keeps labels containing this substring. regex: Regular expression pattern for matching labels. axis: 0 for rows, 1 for columns. Default is None (columns). Filtering by Numeric Index Positions Use iloc[] to filter rows by their ...

Read More

Python Program to Swap dictionary item_s position

Mrudgandha Kulkarni
Mrudgandha Kulkarni
Updated on 27-Mar-2026 315 Views

Dictionaries in Python are versatile data structures that store key-value pairs. Sometimes we need to swap the values of two keys within a dictionary. This article demonstrates different approaches to swap dictionary item values efficiently. Understanding Dictionary Value Swapping When we swap dictionary items, we exchange the values associated with two specific keys. For example, given {'A': 1, 'B': 2, 'C': 3}, swapping values of keys 'A' and 'B' results in {'A': 2, 'B': 1, 'C': 3}. Method 1: Using Tuple Unpacking The most Pythonic way uses simultaneous assignment with tuple unpacking ? def ...

Read More

FileExtensionValidator – Validate File Extensions in Django

Jaisshree
Jaisshree
Updated on 27-Mar-2026 1K+ Views

Django's FileExtensionValidator is a built-in validator that ensures uploaded files have specific extensions. This validator helps maintain security and data integrity by preventing unwanted file types from being uploaded to your application. What is FileExtensionValidator? The FileExtensionValidator allows you to specify which file extensions are allowed or forbidden for FileField and ImageField uploads. It's particularly useful for controlling file types in forms and preventing security vulnerabilities. Basic Usage Here's how to use FileExtensionValidator in your Django models ? from django.db import models from django.core.validators import FileExtensionValidator class Document(models.Model): # ...

Read More
Showing 591–600 of 25,469 articles
« Prev 1 58 59 60 61 62 2547 Next »
Advertisements