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 Vikram Chiluka
Page 2 of 22
Sorting an array in waveform using Python
In this article, we will learn how to sort an array in waveform using Python. A waveform array follows the pattern where arr[0] >= arr[1] = arr[3] = ..., creating alternating peaks and valleys. What is Waveform Sorting? An array is sorted in wave form if elements alternate between being greater than or equal to their neighbors. For example, [4, 3, 12, 6, 25, 15] forms a wave pattern where 4 > 3 < 12 > 6 < 25 > 15. Method 1: Using Built-in sort() Function This approach first sorts the array, then swaps adjacent ...
Read MoreSort the matrix row-wise and column-wise using Python
In this article, we will learn how to sort a matrix both row-wise and column-wise using Python. This technique involves sorting rows first, then transposing the matrix to convert columns into rows, sorting again, and transposing back. We'll implement a solution using nested for loops and matrix transposition to achieve both row-wise and column-wise sorting of an MxM matrix. Algorithm Following are the steps to sort a matrix row-wise and column-wise − Create a function sortingMatrixByRow() to sort each row of the matrix using bubble sort. Create a function transposeMatrix() to swap rows and columns ...
Read MoreRemove list elements larger than a specific value using Python
When working with lists in Python, you often need to remove elements that exceed a certain threshold. Python offers several approaches to filter out elements larger than a specific value. Methods Overview The following methods can be used to remove elements larger than a specific value ? Using remove() Method (with caution) Using List Comprehension Using filter() Method with Lambda Function Using For Loop with append() Using remove() Method Warning: The remove() method can skip elements when modifying a list during iteration. Here's the problematic approach ? # This approach has ...
Read MoreRemove leading zeros from a Number given as a string using Python
In this article, we will learn how to remove leading zeros from a number given as a string using Python. Leading zeros are unnecessary zeros at the beginning of a number that don't affect its mathematical value. We'll explore three effective methods: using lstrip(), regular expressions, and the int() function. Each approach has its own advantages depending on your specific use case. Method 1: Using lstrip() Function The lstrip() method removes specified characters from the beginning of a string. This is the most straightforward approach for removing leading zeros ? def remove_leading_zeros(input_string): ...
Read MorePython program to print matrix in a snake pattern
In this article, we will learn how to print a matrix in a snake pattern. A snake pattern prints the first row left to right, the second row right to left, the third row left to right, and so on, creating a zigzag or snake-like traversal. We will explore two different approaches to accomplish this task using Python. What is a Snake Pattern? Given a matrix, the snake pattern traversal means: Print even-indexed rows (0, 2, 4...) from left to right Print odd-indexed rows (1, 3, 5...) from right to left For example, a ...
Read MorePython program to find Sum of a sublist
In this article, we will learn different methods to find the sum of a sublist in Python. A sublist is a contiguous portion of a list between specified start and end indices. Methods Used The following are the various methods to accomplish this task ? Using For Loop (Brute Force) Using Cumulative Sum Method Using sum() Function Using math.fsum() Function Using For Loop (Brute Force) This method iterates through the sublist elements and adds them one by one ? ...
Read MorePython Program to Convert Singular to Plural
In this article, we will learn a Python Program to Convert Singular to Plural using various methods and libraries. Converting singular words to plural forms is a common task in natural language processing. While basic rules like adding 's' work for many words, English has complex pluralization rules that require more sophisticated approaches. Methods Used The following are the various methods to accomplish this task − Using the regex module Using NLTK and Pattern-en Packages Using the TextBlob module Using inflect module ...
Read MorePython Program to check Involutory Matrix
In this article, we will learn a Python program to check whether a matrix is an Involutory Matrix. An involutory matrix is a special type of square matrix that is its own inverse. What is an Involutory Matrix? An involutory matrix is a square matrix that, when multiplied by itself, gives the identity matrix. In mathematical terms, if A * A = I, then matrix A is called an involutory matrix, where I represents the Identity matrix. Matrix A: 1 ...
Read MorePython Program for Number of local extrema in an array
In this article, we will learn a Python program to find the number of local extrema in an array. A local extrema is an element that is either a local maximum (greater than both neighbors) or a local minimum (less than both neighbors). The first and last elements cannot be extrema since they don't have two neighbors. What are Local Extrema? Consider an array element at position i. It is a local extrema if: Local Maximum: array[i] > array[i-1] and array[i] > array[i+1] Local Minimum: array[i] < array[i-1] and array[i] < array[i+1] ...
Read MoreMatrix and linear Algebra calculations in Python
In this article, we will learn Matrix and linear Algebra calculations in Python such as matrix multiplication, finding determinants, solving linear equations, etc. A matrix object from the NumPy library can be used for this. When it comes to calculation, matrices are relatively comparable to the array objects. Linear Algebra is a huge topic, however, NumPy is an excellent library to start if you need to manipulate matrices and vectors. Operations Covered Finding Transpose of a Matrix Using Numpy Finding Inverse of a Matrix Using Numpy ...
Read More