Pavitra

Pavitra

123 Articles Published

Articles by Pavitra

Page 11 of 13

isupper(), islower(), lower(), upper() in Python and their applications

Pavitra
Pavitra
Updated on 25-Mar-2026 2K+ Views

In this article, we will learn about isupper(), islower(), upper(), and lower() functions in Python. These are built-in string methods that help determine and modify the case of alphabetic characters in strings. These functions are part of Python's Standard Library and work directly on string objects. The isupper() and islower() methods return boolean values, while upper() and lower() return new strings with modified case. Syntax All these methods are called on string objects and accept no arguments: string.isupper() # Returns True if all characters are uppercase string.islower() # Returns True if ...

Read More

Intersection() function Python

Pavitra
Pavitra
Updated on 25-Mar-2026 323 Views

In this article, we will learn about the intersection() function that can be performed on any given set. According to mathematics, intersection means finding common elements from two or more sets. Set A {1, 2, 3, 4} Set B {3, 4, 5, 6} 3, 4 Intersection Set Intersection Syntax .intersection(, , ...) ...

Read More

The intersection of two arrays in Python (Lambda expression and filter function )

Pavitra
Pavitra
Updated on 25-Mar-2026 780 Views

In this article, we will learn about finding the intersection of two arrays in Python using lambda expressions and the filter function. The intersection contains elements that are common to both arrays. The problem is that we are given two arrays and we need to find the common elements between them using functional programming concepts. Algorithm Here's the step-by-step approach ? Declare an intersection function with two array parameters Use a lambda expression with the filter function to select elements from the second array that exist in the first array Convert the filtered result to ...

Read More

Inplace Operators in Python - ixor(), iand(), ipow()

Pavitra
Pavitra
Updated on 25-Mar-2026 351 Views

In this article, we will learn about some of the inplace operators available in Python's operator module. Python provides methods to perform inplace operations, combining assignment and computation simultaneously using a single statement. Here we will discuss three important inplace operators: ixor(), iand(), and ipow() functions. ixor() - Inplace XOR Operation This function performs an inplace XOR (exclusive or) operation. It behaves like the a ^= b operation, computing the bitwise XOR of two values ? import operator as op # using ixor() to perform XOR operation result = op.ixor(786, 12) # displaying ...

Read More

Initialize Matrix in Python

Pavitra
Pavitra
Updated on 25-Mar-2026 4K+ Views

In this article, we will learn how to initialize a matrix using two dimensional lists in Python. A matrix is a rectangular array of numbers arranged in rows and columns, which can be represented as a list of lists in Python. Let's explore different methods to initialize matrices, taking advantage of Python's list comprehension feature for clean and efficient code. Method 1: Using List Comprehension List comprehension provides an intuitive way to initialize matrices. We create the inner lists first and then extend to multiple rows ? # Define matrix dimensions rows = 3 cols ...

Read More

Python Program for Counting Sort

Pavitra
Pavitra
Updated on 11-Mar-2026 273 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement− We are given an array, we need to sort the array using the concept of counting sort.Counting sort is a technique in which we work on keys between a specific range. It involves counting the number of objects which have distinct key & values. Finally, we do arithmetic calculations to obtain the position of each object and display the output.Now let’s observe the solution in the implementation below −Exampledef countSort(arr):    # The output character array that will have sorted arr    output = ...

Read More

Python Program for Cycle Sort

Pavitra
Pavitra
Updated on 11-Mar-2026 351 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to sort it using the concept of cycle sort.It is an in-place algorithm and swapping takes place by the formation of cycles.Now let’s observe the solution in the implementation below −Exampledef cycleSort(array):    writes = 0    # cycles to be rotated    for cycleStart in range(0, len(array) - 1):       item = array[cycleStart]       #position to place the item       pos = cycleStart       for i in range(cycleStart ...

Read More

Python Program for Egg Dropping Puzzle

Pavitra
Pavitra
Updated on 11-Mar-2026 384 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − Suppose that we want to know which stories in a 40-story building are safe to drop the eggs from, and which of those will cause the eggs to get damaged on landing with the help of eggs. We need to display a minimum number of trails to check the stories.Now let’s observe the solution in the implementation below −Example# dynamic programming INT_MAX = 32767 # to get minimum trials def eggDrop(n, k):    # intialization    eggFloor = [[0 for x in range(k + ...

Read More

Python Program for Extended Euclidean algorithms

Pavitra
Pavitra
Updated on 11-Mar-2026 2K+ Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − Given two numbers we need to calculate gcd of those two numbers and display them.GCD Greatest Common Divisor of two numbers is the largest number that can divide both of them. Here we follow the euclidean approach to compute the gcd i.e. to repeatedly divide the numbers and stop when the remainder becomes zero. Here we extend the algorithm based on previous values obtained in recursion.Now let’s observe the solution in the implementation below −Example# extended Euclidean Algorithm def gcdExtended(a, b, x, y):   ...

Read More

Python Program for Find the closest pair from two sorted arrays

Pavitra
Pavitra
Updated on 11-Mar-2026 294 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given two arrays, we need to find the closest pair from the two sorted arraysNow let’s observe the solution in the implementation below −Example# sys module import sys # pair def print_(ar1, ar2, m, n, x):    # difference    diff=sys.maxsize    # index    l = 0    r = n-1    while(l < m and r >= 0):    # closest pair       if abs(ar1[l] + ar2[r] - x) < diff:          res_l = l ...

Read More
Showing 101–110 of 123 articles
« Prev 1 9 10 11 12 13 Next »
Advertisements