Found 10784 Articles for Python

Sorting an array in waveform using Python

Vikram Chiluka
Updated on 01-Feb-2023 20:04:29

532 Views

In this article, we will learn a python program to sort an array in the waveform. Assume we have taken an unsorted input array. We will now sort the input array in a waveform. An array ‘arr[0..n-1]’ is sorted in wave form if arr[0] >= arr[1] = arr[3] = ….. Methods Used The following are the various methods used to accomplish this task &miinus; Using Built-in sort() function Without Using Built-in functions Method 1: Using the Built-in sort() function Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create a function ... Read More

Sort the matrix row-wise and column-wise using Python

Vikram Chiluka
Updated on 31-Jan-2023 13:52:02

1K+ Views

In this article, we will learn a python program to sort the matrix row-wise and column-wise. Assume we have taken an input MxM matrix. We will now sort the given input matrix row-wise and column-wise using the nested for loop. Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create a function sortingMatrixByRow() to sort each row of matrix i.e, row-wise by accepting input matrix, m(no of rows) as arguments. Inside the function, use the for loop to traverse through the rows of a matrix. Use Another nested for loop to traverse ... Read More

Remove list elements larger than a specific value using Python

Vikram Chiluka
Updated on 31-Jan-2023 13:49:54

6K+ Views

In this article, we will learn how to remove elements larger than a specific value from a list in Python. Methods Used The following are the various methods used to accomplish this task − Using remove() Method Using List Comprehension Using the filter() method & lambda function Method 1: Using remove() Method remove() function(removes the first occurrence of the element from the list) Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create a variable to store the input list. Create another variable to store another input value. Use the for ... Read More

Remove leading zeros from a Number given as a string using Python

Vikram Chiluka
Updated on 31-Jan-2023 13:46:49

11K+ Views

In this article, we will learn a python program to remove leading zeros from a number given as a string. Assume we have taken a number in string format. We will now remove all the leading zeros(zeros present at the beginning of a number) using the below-given methods. Methods Used The following are the various methods used to accomplish this task − Using For Loop and remove() function Using Regex Using int() Function Method 1: Using For Loop and remove() function Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create ... Read More

Python program to print matrix in a snake pattern

Vikram Chiluka
Updated on 31-Jan-2023 13:45:34

2K+ Views

In this article, we will learn a python program to print a matrix in a snake pattern. Assume we have taken the n x n matrix. We will now print the input matrix in a snake pattern using the below-mentioned methods. Methods Used The following are the various methods used to accomplish this task − Using the nested for loop Reversing Alternate Rows Using Slicing Intuition  We will iterate through all the rows of a matrix. For each row, we will now check whether it is even or odd. If the row is even, then will print the ... Read More

Python program to find Sum of a sublist

Vikram Chiluka
Updated on 31-Jan-2023 13:44:19

2K+ Views

In this article, we will learn a python program to find the sum of a sublist. Methods Used The following are the various methods to accomplish this task − Using For Loop(Brute Code) Using Cumulative Sum Method Using sum() Function Using math.fsum() Function Using For Loop (Brute Code) Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task. − Create a variable to store the input list. Create two separate variables for storing the start and the end indices. Initialize a variable resultSum to 0 for storing the resultant sum of a sublist. ... Read More

Python Program to Convert Singular to Plural

Vikram Chiluka
Updated on 01-Feb-2023 20:12:54

4K+ Views

In this article, we will learn a Python Program to Convert Singular to Plural. Assume you are given a singular word and we must convert it into plural using the various python methods. 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 Method 1: Using the regex module The regex module in python searches for a string or group of strings based on a specified pattern. In case it doesn't already exist in your Python you must install ... Read More

Python Program to check Involutory Matrix

Vikram Chiluka
Updated on 31-Jan-2023 13:42:45

88 Views

In this article, we will learn a python program to check Involutory Matrix. Assume we have taken an input matrix. We will now check whether the input matrix is an Involutory Matrix using the below methods. Methos Used The following are the various methods to accomplish this task − Using Nested For Loop Using NumPy module What is an Involutory Matrix? If a matrix multiplies by itself and gives the identity matrix, it is said to be an involutory matrix. The matrix that is its inverse is the involutory matrix. If A * A = I, matrix A ... Read More

Python Program for Number of local extrema in an array

Vikram Chiluka
Updated on 31-Jan-2023 13:40:39

296 Views

In this article, we will learn a python program for a number of local extrema in an array. An extrema is an element that is either greater than or less than both of its neighbors. Assume we have taken an array containing n elements. We will now find the count of a number of local extrema in a specified input array. Note The first and last elements are not extrema. Using For loop NOTE Both array[0] and array[n-1] have only one neighbor each, hence they are neither minima nor maxima. len() − The number of items in an ... Read More

Additive Secret Sharing and Share Proactivization ñ Using Python

Satish Kumar
Updated on 31-Jan-2023 13:37:47

389 Views

Additive Secret Sharing is a method of sharing a secret among a group of participants in such a way that the secret can only be reconstructed if a certain number of participants come together and provide their shares. This technique is widely used in cryptography and secure multiparty computation. In this article, we will discuss the concept of Additive Secret Sharing and Share Proactivization and how they can be implemented using Python. Introduction to Additive Secret Sharing Additive Secret Sharing is a technique that allows a group of participants to share a secret among themselves without revealing the secret to ... Read More

Advertisements