Programming Articles

Page 154 of 2547

Python Program for Number of local extrema in an array

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 537 Views

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 More

Additive Secret Sharing and Share Proactivization ñ Using Python

Farhan Muhamed
Farhan Muhamed
Updated on 27-Mar-2026 727 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 ...

Read More

Matrix and linear Algebra calculations in Python

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 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, 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

Python Program to Test if any set element exists in List

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 3K+ Views

In this article, we will learn how to check if any set element exists in a list using three different Python methods. Methods Used Using any() function Using bitwise & operator Using Counter(), filter() and lambda functions Example Problem We have an input set and input list. We need to check whether any element from the set exists in the list ? Input inputSet = {4, 8, 1, 3, 5, 7} inputList = [7, 15, 20] Expected Output Checking whether any set element present in the input ...

Read More

Python Program to Subtract K from each digit

Ranbir Kapoor
Ranbir Kapoor
Updated on 27-Mar-2026 204 Views

In this article, we will learn how to write a Python program that subtracts a given value K from each digit of numbers in a list. When the result becomes negative, we use 0 instead. Given an input list containing numbers and a K value, we subtract K from each individual digit and return the modified numbers. Example Let's understand with an example ? Input list = [1034, 356, 2145, 6712, 8671] K value = 3 For the number 1034, we subtract 3 from each digit: 1 − 3 = −2 ...

Read More

Python Program to Split a String by Custom Lengths

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 3K+ Views

In this article, we will learn how to split a string by custom lengths in Python. This technique is useful when you need to break a string into segments of specific sizes, such as parsing fixed-width data formats or creating chunks for processing. Methods Used The following are the various methods to accomplish this task − Using for loop and slicing Using List Comprehension with iter() and next() functions Problem Overview Let's understand the problem with an example. Assume we have an input string and custom lengths ...

Read More

Python Program to Sort A List Of Names By Last Name

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 2K+ Views

In this article, we will learn how to sort a list of names by last name using Python. This is a common task when working with name data that needs alphabetical ordering by surname. Methods Used Using lambda with sorted() function Using lambda with sort() method Example Overview Let's assume we have a list containing full names as strings. We need to sort these names alphabetically by their last names ? Input names = ['sachin tendulkar', 'suresh raina', 'hardik pandya'] Expected Output ['hardik pandya', 'suresh raina', 'sachin tendulkar'] ...

Read More

Python Program to Replace all words except the given word

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 450 Views

In this article, we will learn how to replace all words except the given word in a string in Python. This technique is useful for text processing where you want to mask certain words while preserving specific keywords. Methods Used The following are the various methods to accomplish this task: Using For Loop, split() & join() Functions Using List Comprehension Problem Statement Given an input string, we need to replace all words with a replacement character except for one specific word that should remain unchanged. Input ...

Read More

Python Program to Remove numbers with repeating digits

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 1K+ Views

In this article, we will learn how to remove numbers with repeating digits from a list in Python. Numbers like 3352 (3 appears twice) or 661 (6 appears twice) will be filtered out, keeping only numbers with unique digits. Problem Example Given an input list of numbers, we need to remove all numbers containing repeating digits ? Input inputList = [3352, 8135, 661, 7893, 99] Expected Output [8135, 7893] In the above example, 3352 has digit 3 repeated twice, 661 has digit 6 repeated, and 99 has digit 9 ...

Read More

Python program to remove K length words in String

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 686 Views

In this article, we will learn how to remove all words of a specific length (K) from a string using Python. This is useful for text processing tasks where you need to filter words based on their character count. Problem Statement Given an input string and a value K, we need to remove all words that have exactly K characters and return the modified string. Example inputString = "hello tutorialspoint python codes" k_length = 5 The output will be ? Resultant string after removing 5 length words: tutorialspoint python ...

Read More
Showing 1531–1540 of 25,466 articles
« Prev 1 152 153 154 155 156 2547 Next »
Advertisements