Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

Python program to remove Nth occurrence of the given word

Python Program to Remove Nth Occurrence of a Given Word Introduction In text processing and manipulation, there may be scenarios where you need to remove a specific occurrence of a word from a given text. This Python program demonstrates how to remove the Nth occurrence of a specified word from a string. Understanding the Algorithm…
Read more

Python program to swap two elements in a list

Python program to swap two elements in a list Given a list in Python and provided the positions of the elements, write a program to swap the two elements in the list. Examples: Input : List = [23, 65, 19, 90], pos1 = 1, pos2 = 3 Output : [19, 65, 23, 90] Input :…
Read more

Python program to interchange first and last elements in a list

Python program that interchanges the first and last elements of a list: In this program, the interchange_first_last() the function takes a list as its argument and returns the list with its first and last elements interchanged. The function first checks if the list has at least two elements. If it does, the function swaps the…
Read more

Python Program to check if the given array is Monotonic

Python Program: Check Monotonic Array In this blog post, we’ll explore a Python program that checks whether a given array is monotonic or not. A monotonic array is one that is entirely non-increasing or non-decreasing. The program takes an array as input, performs the necessary checks, and outputs whether the array is monotonic or not.…
Read more

Reconstruct the array by replacing arr[i] with (arr[i-1]+1) % M

Reconstructing an Array: Replace arr[i] with (arr[i-1]+1) % M In this blog post, we’ll explore a Python program that reconstructs an array by replacing each element arr[i] with (arr[i-1] + 1) % M, where M is a given positive integer. The article will walk through the algorithm used in the program, provide the Python code…
Read more

Python Program for Find remainder of array multiplication divided by n

Python Program to Find the Remainder of Array Multiplication Divided by N Introduction In this Python program, we will focus on finding the remainder when the product of all elements in an array is divided by a given number N. The program takes an array of integers as input, multiplies all its elements, and then…
Read more

Python Program to Split the array and add the first part to the end

Python Program to Split the array and add the first part to the end There is a given an array and split it from a specified position, and move the first part of array add to the end. Examples: Input : arr[] = {12, 10, 5, 6, 52, 36} k = 2 Output : arr[]…
Read more

Python Program for Reversal algorithm for array rotation

Python Program for Reversal algorithm for array rotation Write a function rotate(arr[], d, n) that rotates arr[] of size n by d elements.

Python Program for array rotation

Python Program for array rotation Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.

Python Program to find largest element in an array

Python Program to find largest element in an array Given an array, find the largest element in it. Input : arr[] = {10, 20, 4} Output : 20 Input : arr[] = {20, 10, 20, 4, 100} Output : 100 Python3 # Python3 program to find maximum # in arr[] of size n    #…
Read more