Found 10476 Articles for Python

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

3K+ 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

5K+ 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

154 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

442 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

Farhan Muhamed
Updated on 11-Jul-2025 18:24:17

578 Views

Additive Secret Sharing and Share Proactivization are cryptographic techniques to share a password or other confidential data among a group of people. In this article, we will explain these techniques and implement Python code to demonstrate them. Additive Secret Sharing Additive secret sharing is a technique used in cryptography to share a secret string or a password among multiple parties, such that all of the parties must collaborate to reconstruct the secret. For example: Original Secret Key: 1234 Generated five Shares: [-488, -55, -417, -720, 2914] Reconstructed Secret: 1234 Explanation: The original secret password is split into 5 ... Read More

Matrix and linear Algebra calculations in Python

Vikram Chiluka
Updated on 01-Feb-2023 20:10:57

1K+ Views

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 that is outside of this article. However, NumPy is an excellent library to start if you need to manipulate matrices and vectors. Methods Used Finding Transpose of a Matrix Using Numpy Finding Inverse of a Matrix Using Numpy Multiplying Matrix with a Vector ... Read More

Python program to Uppercase selective indices

Vikram Chiluka
Updated on 27-Jan-2023 12:22:26

2K+ Views

In this article, we will learn a python program to convert the string elements to uppercase for the given selective indices. Methods Used The following are the various methods to accomplish this task − Using For Loop and upper() function Using List Comprehension Using index() & join() functions Example Assume we have taken an input string and a list containing index values. We will now convert the characters of an input string to uppercase at those given indices and print the resultant string. Input inputString = 'hello tutorialspoint python' indexList = [0, 6, 8, 10, 15, ... Read More

Python Program to Test if string contains element from list

Vikram Chiluka
Updated on 27-Jan-2023 12:28:22

1K+ Views

In this article, we will learn how to check if a string contains an element from a list in python. Methods Used Using Nested For Loops Using List Comprehension Using any() function Using the find() function Example Assume we have taken an input string and input list. We will now check whether the input string contains at least any one input list element. Input inputString = "tutorialspoint is a best learning platform for coding" inputList = ['hello', 'tutorialspoint', 'python'] Output YES, the string contains elements from the input list In the above example, the ... Read More

Python Program to Test if any set element exists in List

Vikram Chiluka
Updated on 27-Jan-2023 12:19:16

3K+ Views

In this article, we will learn how to check if any set element exists in the list in python. Methods Used Using any() function Using Bitwise & operator Using Counter(), filter() and lambda functions Example Assume we have taken an input set and input list. We will now check whether any input set element exists in the input list using the above methods. Input inputSet = {4, 8, 1, 3, 5, 7} inputList = [7, 15, 20] Output Checking whether any set element present in the input list: True In the above example, 7 exists ... Read More

Advertisements