Programming Articles

Page 619 of 2547

Python Helpers for Computing Deltas

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 323 Views

The difflib module in Python provides tools for computing deltas between sequences. It's particularly useful for comparing files and generating difference reports in various formats including HTML, context, and unified diffs. import difflib SequenceMatcher Class The difflib.SequenceMatcher class compares two sequences of any type and provides detailed comparison methods ? Key Methods set_seqs(a, b) − Set both sequences to compare. Computes and caches detailed information about the second sequence. set_seq1(a) − Set the first sequence to compare. set_seq2(b) − Set the second sequence to compare. find_longest_match(alo, ahi, blo, bhi) − Find the ...

Read More

Python GNU readline Interface

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 992 Views

The readline module is a UNIX-specific interface to the GNU readline library. It provides functions to manage command history, line editing, and tab completion in Python's interactive interpreter. This module can enhance the user experience by enabling features like command history persistence and custom completion. For macOS systems, the readline module may use the libedit library instead of GNU readline, which has different configuration options. Importing the Module To use the readline functionality, import the module in your Python code ? import readline Key Functions Function Description readline.parse_and_bind(string) ...

Read More

Python Context Manager Types

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 267 Views

Python context managers enable automatic resource management using the with statement. They define what happens when entering and exiting a runtime context, ensuring proper cleanup of resources like files, database connections, or locks. Context managers implement two special methods to define their behavior ? The __enter__() Method The __enter__() method is called when entering the runtime context. It sets up the resource and returns an object that will be assigned to the variable after the as keyword in the with statement. class SimpleContext: def __enter__(self): ...

Read More

Python Sequence Types

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 11K+ Views

In Python programming, sequence types are fundamental data structures that hold an ordered collection of items. The main sequence types include Lists, Strings, Tuples, and Range objects. These data structures allow us to access their elements through indexing and iteration. Sequence Types in Python Sequence types in Python are categorized into two main types: mutable and immutable sequences. Mutable Sequence Types These sequences can be changed after their creation. You can modify elements, add new elements, and remove existing ones. Lists: A mutable, ordered collection of items that can store ...

Read More

Python program for removing n-th character from a string?

Akshitha Mote
Akshitha Mote
Updated on 25-Mar-2026 1K+ Views

Removing the nth character from a string is a common string manipulation task in Python. We can accomplish this using several approaches: for loops, string slicing, or the replace() method. Let's explore each method with examples. Understanding the Problem When removing the nth character, remember that Python uses zero-based indexing. So the 1st character is at index 0, the 2nd character is at index 1, and so on. To remove the nth character, we target index n-1. Using a For Loop The for loop approach iterates through each character and skips the one at the target ...

Read More

Python program to check for URL in a string

Sarika Singh
Sarika Singh
Updated on 25-Mar-2026 3K+ Views

This article will teach you how to determine whether a string contains a URL or not. In Python, strings are collections of bytes that represent Unicode characters. When given a string, we will first determine whether it contains a URL and then extract it using regular expressions. Using findall() Method We will use Python's regular expression concept to solve this problem. Regular expressions are supported by the Python re module. The findall() method returns a list of all matches found in the string, scanning from left to right. Syntax re.findall(pattern, string) Example ...

Read More

How to insert a Python object in MySQL?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 25-Mar-2026 1K+ Views

To insert Python objects like tuples, lists, or dictionaries into a MySQL database, you need to establish a connection and use parameterized queries. This tutorial shows how to safely insert Python data structures into MySQL tables. Prerequisites First, install the PyMySQL module and ensure you have a MySQL database with an employee table ? pip install PyMySQL Create the employee table structure ? CREATE TABLE employee ( fname VARCHAR(50), lname VARCHAR(50), age INT, gender CHAR(1), ...

Read More

Python Program to print unique values from a list

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 3K+ Views

List is a built-in data structure in python which functions like a dynamically sized array. Lists are created by putting elements in square brackets [element1, element2, ....]. Elements present in list are indexed and the indexing starts from [0]. List has the following properties − List is mutable meaning that elements can be added, removed or changed from a list after its creation. List is ordered, so adding new elements to the list ...

Read More

Python program to sort a tuple by its float element

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 2K+ Views

This article demonstrates how to sort a list of tuples by their float elements in Python. We'll explore three different approaches: using sorted(), using sort(), and implementing bubble sort manually. Input-Output Scenarios The following scenarios show how tuples are sorted by their float elements in descending order ? Scenario 1 Input: data = [('Dengue', '54.865'), ('Malaria', '345.743'), ('Corona', '456.864'), ('Typhoid', '35.285'), ('Jaundice', '83.367')] Output: [('Corona', '456.864'), ('Malaria', '345.743'), ('Jaundice', '83.367'), ('Dengue', '54.865'), ('Typhoid', '35.285')] Scenario 2 Input: data = [('638', '54.865'), ('932', '345.743'), ('256', '456.864'), ('843', '35.285'), ('246', '83.367')] Output: [('256', ...

Read More

Python Program to find mirror characters in a string

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 3K+ Views

This article teaches you how to write a Python program to find mirror characters in a string. A mirror character is the alphabetically opposite character − 'a' mirrors to 'z', 'b' to 'y', and so on. Understanding Mirror Characters Mirror characters are pairs of letters that are equidistant from both ends of the alphabet. For example: 'a' (1st letter) mirrors to 'z' (26th letter) 'b' (2nd letter) mirrors to 'y' (25th letter) 'c' (3rd letter) mirrors to 'x' (24th letter) Input-Output Example Given a string and a position, we mirror characters from that ...

Read More
Showing 6181–6190 of 25,466 articles
« Prev 1 617 618 619 620 621 2547 Next »
Advertisements