Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Yaswanth Varma
Page 4 of 31
SequenceMatcher in Python for Longest Common Substring.
The SequenceMatcher class is part of Python's difflib module. It compares sequences (such as lists or strings) and finds similarities between them. The task is to find the Longest Common Substring — the longest sequence of characters that appears contiguously in both strings. This is different from the Longest Common Subsequence, where characters may appear in the same order but not necessarily contiguous. Using find_longest_match() Method The find_longest_match() method finds the longest matching sequence of elements between two sequences. It returns a Match object with three attributes: a (start position in first sequence), b (start position in ...
Read MorePython program to find Maximum and minimum element’s position in a list?
In Python, Lists are one of the most versatile data types. They store sequences of comma-separated items enclosed in square brackets []. Finding the maximum and minimum element positions is a common task that can be achieved using Python's built-in functions max(), min(), and index(). Understanding the Required Functions max() Function The max() function returns the largest element in a list. For numbers, comparison is done numerically; for strings, comparison is done alphabetically. max(list) min() Function The min() function returns the smallest element in a list. Like max(), it compares numbers numerically ...
Read MorePython program to check if binary representation of two numbers are anagram.
The binary numbers are the basis of how data is stored, processed and transferred. Every integer is internally represented by using a sequence of bits (combination of 0s and 1s). In this article, we will learn how to check if binary representation of two numbers are anagram. Two numbers are said to be binary anagrams if their binary representations contain the same number of 1s and 0s. For example, the number 12 in binary is 1100 and the number 10 in binary is 1010, both have two 0s and two 1s, making them binary anagrams. Using collections.Counter() Class ...
Read MorePython program to find missing and additional values in two lists?
In this article, we will explore how to find missing and additional values in two lists. This type of comparison is commonly encountered in real-world scenarios such as data validation, system synchronization, and database reconciliation. The task is to determine which elements are missing in one list and what unexpected elements were received. This can be achieved by using Python's built-in data structures like sets that allow for efficient comparison operations. Understanding the Problem When comparing two lists, we need to identify: Missing values: Elements present in the first list but absent in the second list ...
Read MorePython program to list the difference between two lists.
In Python, Lists are one of the built-in data types used for storing collections of data. Python lists are sequences of comma-separated items, enclosed in square brackets []. They are flexible, easy to manipulate and widely used in various applications. In this article, we will explore different methods to find the difference between two lists. Python provides several built-in approaches for achieving this. Using set.difference() Method The Python set.difference() method returns a new set containing elements that are present in the first set but not in any other sets provided as arguments. Syntax set.difference(*others) ...
Read MorePython program to print all distinct elements of a given integer array.
The distinct elements are the values that appear only once or uniquely in an array. When working with arrays, we often encounter repeated or duplicate values. In this article, we will explore different methods to print all distinct elements of a given integer array. Identifying and printing these distinct elements is a common task to avoid unexpected results. This can be achieved using Python built-in tools like sets, dictionaries, and loops. Using Python set() Function In this approach, we use the Python set() function, which automatically removes all duplicate values from the list because a set only ...
Read MorePython program to print a checkboard pattern of n*n using numpy.
The checkboard pattern is a square grid composed of alternating 0s and 1s, arranged in a way that no two adjacent cells have the same value. It looks like a chessboard, where black and white squares alternate in every row and column. This pattern is commonly used in chess, checkers, image processing, graphics, and visualization. In this article, we'll learn how to create a checkboard pattern of n×n using NumPy. Using numpy.indices() Method The numpy.indices() method returns a grid of indices with the given shape. It creates coordinate matrices from coordinate vectors that we can use to ...
Read MorePython program to communicate between parent and child process using the pipe.
Inter-process communication (IPC) is essential when multiple processes need to share data and work together. In Python, the multiprocessing module provides various IPC mechanisms, one of which is the pipe. A pipe allows data to be transferred between processes in either two-way (duplex) or one-way mode. It is particularly useful when a parent process creates a child process and they need to exchange messages or data. Python multiprocessing.Pipe() Method The multiprocessing.Pipe() method returns a pair of connection objects connected by a pipe. This pipe enables sending and receiving data between two processes. Syntax multiprocessing.Pipe(duplex=True) ...
Read MorePython program to iterate over multiple lists simultaneously?
In this article, we are going to learn how to iterate over multiple lists simultaneously. This is useful when the lists contain related data. For example, one list stores names, another stores ages, and a third stores grades. By iterating over these lists simultaneously, we can access the complete information for each item. Using zip() Function The Python zip() function is a built-in function used to combine elements from two or more iterable objects (such as lists, tuples, etc) and returns an iterator. The resultant iterator contains tuples where the ith tuple contains the ith element from each ...
Read MoreMap function and Dictionary in Python to sum ASCII values
In this article, we are going to learn how to use the map() function along with dictionaries to sum the ASCII values of characters in strings. The Python built-in ord() function returns the ASCII integer value of a character. Additionally, dictionaries (dict) in Python are used to store key-value pairs. We use them to associate strings with their total ASCII values, making it easy to store and retrieve results. Python map() Function The Python map() function applies a function to every item in an iterable and returns a map object. Here's the syntax ? map(function, ...
Read More