Articles on Trending Technologies

Technical articles with clear explanations and examples

Python program for Modular Exponentiation

Akshitha Mote
Akshitha Mote
Updated on 24-Mar-2026 1K+ Views

Modular exponentiation calculates (baseexponent) % modulo efficiently. This operation is fundamental in cryptography and number theory, involving three integers: base, exponent, and modulo. Syntax # Basic syntax result = (base ** exponent) % modulo # Using pow() function (recommended) result = pow(base, exponent, modulo) Basic Example Let's calculate (25) % 5 step by step ? base = 2 exponent = 5 modulo = 5 # Step by step calculation power_result = base ** exponent print(f"{base}^{exponent} = {power_result}") final_result = power_result % modulo print(f"{power_result} % {modulo} = {final_result}") ...

Read More

String slicing in Python to rotate a string

karthikeya Boyini
karthikeya Boyini
Updated on 24-Mar-2026 5K+ Views

String rotation involves moving characters from one end of a string to the other. Python's string slicing makes this operation simple and efficient. We can rotate strings in two directions: left rotation (anticlockwise) and right rotation (clockwise). Understanding String Rotation Given a string and a rotation distance d: Left Rotation: Move first d characters to the end Right Rotation: Move last d characters to the beginning Example Input: string = "pythonprogram" d = 2 Output: Left Rotation: thonprogrampy Right Rotation: ampythonprogr Algorithm ...

Read More

Python program to move spaces to front of string in single traversal

Samual Sam
Samual Sam
Updated on 24-Mar-2026 601 Views

Given a string that has set of words and spaces, our task is to move all spaces to front of string, by traversing the string only once. We will solve this problem quickly in Python using list comprehension. Example Input: string = "python program" Output: string = " pythonprogram" Algorithm The algorithm follows these steps: Input a string with words and spaces Traverse the input string using list comprehension to extract non-space characters Calculate the number of spaces in ...

Read More

Program to check if a number is Positive, Negative, Odd, Even, Zero?

Samual Sam
Samual Sam
Updated on 24-Mar-2026 8K+ Views

In this article, we are going to learn how to check if the number is positive, negative, odd, even, or zero. Identifying and categorizing a number based on its characteristics is a basic operation. A number can fall into multiple categories: Positive: A number is greater than 0. Negative: A number less than 0. Zero: The number that is equal to 0. Even: A number that is divisible by 2. Odd: A number that is not divisible by ...

Read More

Python program to print all sublists of a list.

Yaswanth Varma
Yaswanth Varma
Updated on 24-Mar-2026 6K+ Views

A sublist is a portion of a list containing one or more elements from the original list. Sublists can be contiguous (elements appear in the same order as the original) or non-contiguous (elements are taken from different positions). Printing Contiguous Sublists Using Nested Loops Contiguous sublists maintain the original order of elements. We can generate them using nested loops ? def print_contiguous_sublists(items): for i in range(len(items)): for j in range(i, len(items)): print(items[i:j+1]) ...

Read More

Concatenated string with uncommon characters in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 24-Mar-2026 1K+ Views

In Python, Strings are one of the commonly used data types that are used to store sequences of characters. In this article, we are going to learn to concatenate strings with uncommon characters in Python. The uncommon characters are the characters that appear in one string but not in the other string. For example, if str1="ABC" and str2="BCD", the uncommon characters are 'A' and 'D', and the concatenated result is "AD". Using set.symmetric_difference() Method The set.symmetric_difference() method returns a new set that contains elements present in either of the sets, but not in both. This makes it ...

Read More

Python program to print all the common elements of two lists.

Chandu yadav
Chandu yadav
Updated on 24-Mar-2026 1K+ Views

Given two lists, we need to find and print all the common elements between them. Python provides several approaches to solve this problem efficiently. Examples Input : list1 = [5, 6, 7, 8, 9] list2 = [5, 13, 34, 22, 90] Output : {5} Explanation The common element between both lists is 5, which appears in both lists. Using Set Intersection Convert both lists to sets and use the intersection operator (&) to find common elements ? def find_common_elements(list1, list2): ...

Read More

Python Program to calculate n+nm+nmm.......+n(m times).

Samual Sam
Samual Sam
Updated on 24-Mar-2026 617 Views

Here we need to calculate a series where each term is formed by repeating digit n multiple times: n + nn + nnn + ... up to m terms. For example, if n=3 and m=4, the series would be 3 + 33 + 333 + 3333. Algorithm Step 1: Input n and m values Step 2: Convert n to string for concatenation Step 3: Initialize sum with first term (n) Step 4: Build each term by concatenating n repeatedly Step 5: Convert string back to integer and add to sum Step 6: Return final sum ...

Read More

Python program to display Astrological sign or Zodiac sign for a given data of birth.

Akshitha Mote
Akshitha Mote
Updated on 24-Mar-2026 5K+ Views

In this article, we'll learn how to determine the astrological sign or zodiac sign for a given date of birth. We'll compare the user's birthdate with predefined date ranges for each zodiac sign using Python programming logic. The 12 astrological sun signs, also known as zodiac signs, are based on specific periods throughout the year. Each sign corresponds to a particular range of dates ? Aries (March 21 − April 19) Taurus (April 20 − May 20) Gemini (May 21 − June 20) Cancer (June ...

Read More

Python program to create 3D list.

Yaswanth Varma
Yaswanth Varma
Updated on 24-Mar-2026 2K+ Views

In Python, a 3D list is also called a three-dimensional array (list of lists of lists). It can be visualized as a cube or a set of tables stacked together. It is commonly used to represent data with three indices, such as a matrix of images (height, width, depth) or storing data for multiple 2D grids. In this article, we will learn how to create a 3D list. While Python doesn't have built-in support for multi-dimensional arrays like other programming languages, we can create and manipulate 3D lists using nested lists and loops. Using Nested Loops The ...

Read More
Showing 7231–7240 of 61,303 articles
« Prev 1 722 723 724 725 726 6131 Next »
Advertisements