Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

Python Program for Iterative Quick Sort

Python Program for Iterative Quick Sort # Python program for implementation of Quicksort    # This function is same in both iterative and recursive def partition(arr,l,h):     i = ( l – 1 )     x = arr[h]       for j in range(l , h):         if   arr[j] <= x:               # increment index of smaller element             i…
Read more

Python Program for QuickSort

Python Program for QuickSort Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot.

Python Program for Recursive Insertion Sort

Python Program for Recursive Insertion Sort Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. Below is an iterative algorithm for insertion sort Algorithm // Sort an arr[] of size n insertionSort(arr, n) Loop from i = 1 to n-1. a) Pick element arr[i] and insert…
Read more

Python Program for Insertion Sort

Python Program for Insertion Sort Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. # Python program for implementation of Insertion Sort   # Function to do insertion sort def insertionSort(arr):       # Traverse through 1 to len(arr)     for i in range(1, len(arr)):           key =…
Read more

Python Program for Linear Search

Python Program for Linear Search Problem: Given an array arr[] of n elements, write a function to search a given element x in arr[]. Examples : Input : arr[] = {10, 20, 80, 30, 60, 50, 110, 100, 130, 170} x = 110; Output : 6 Element x is present at index 6 Input :…
Read more

Python Program for Binary Search (Recursive and Iterative)

Python Binary Search: Recursive and Iterative Approaches Explained Binary search is a fundamental algorithm used for efficiently locating a target element in a sorted list or array. It follows the divide and conquer strategy, significantly reducing the search space with each comparison. In this blog post, we will explore both recursive and iterative implementations of…
Read more

Python program to create a list of tuples from given list having number and its cube in each tuple

Python Program: Create a List of Tuples with Number and Its Cube Introduction In this blog post, we will explore how to write a Python program to create a list of tuples where each tuple contains a number and its cube. We’ll discuss the algorithm, provide a step-by-step explanation, present the Python code, and include…
Read more

Execute a String of Code in Python

Execute a String of Code in Python Given few lines of code inside a string variable and execute the code inside the string. Examples: Input: code = “”” a = 6+5 print(a)””” Output: 11 Explanation: Mind it that “code” is a variable and not python code. It contains another code, which we need to execute.…
Read more

Python | Permutation of a given string using inbuilt function

Python | Permutation of a given string using inbuilt function A permutation, also called an “arrangement number” or “order”, is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation. Examples: Input : str = ‘ABC’ Output : ABC ACB…
Read more

+Python | Swap commas and dots in a String

Python Program: Swap Commas and Dots in a String In this blog post, we’ll explore a Python program that swaps commas and dots in a given string. The program will take a string as input, swap occurrences of commas (,) with dots (.) and vice versa, and then output the modified string. We’ll discuss the…
Read more