Python Articles

Page 636 of 855

Program to encrypt a string using Vigenere cipher in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 5K+ Views

The Vigenère cipher is a classic encryption technique that shifts each character in a text by a different amount based on a key. Each character in the text is shifted by the corresponding character in the key, where A=0, B=1, C=2, and so on. For example, if we have text = "code" and key = "team", each letter gets shifted: 'c' + 't'(19) = 'v' 'o' + 'e'(4) = 's' 'd' + 'a'(0) = 'd' 'e' + 'm'(12) = 'q' Algorithm Steps To implement the Vigenère cipher, we follow these steps − Create an ...

Read More

Program to encrypt a string using Vertical Cipher in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 368 Views

The Vertical Cipher is an encryption technique that rearranges a string by distributing characters into columns and reading them vertically. Given a string and number of rows, we arrange the string into a grid and extract each column to form encrypted segments. For example, with string "ilovepythonprogramming" and n = 5 rows, we arrange characters into 5 rows and read each column from top to bottom, left to right. How Vertical Cipher Works The algorithm distributes characters across n rows in a round-robin fashion ? Original: "ilovepythonprogramming" Arranged ...

Read More

Program to find the resolved Unix style path in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 246 Views

In Unix systems, paths can contain special directory symbols: ".." represents the parent directory and "." represents the current directory. When given a path as a list of strings, we need to resolve these symbols to find the actual final path. For example, if we have ["usr", "..", "usr", ".", "local", "etc", "foo"], this represents the path /usr/../usr/./local/etc/foo which resolves to /usr/local/etc/foo. Algorithm The solution uses a stack-based approach ? Create an empty stack (list) to store resolved path components For each element in the path: If element is "..": pop from stack (go ...

Read More

Program to find the number of unique integers in a sorted list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 333 Views

Finding the number of unique integers in a sorted list is a common programming task. Python provides several efficient approaches to solve this problem, from using built-in data structures to leveraging the sorted nature of the list. So, if the input is like nums = [3, 3, 3, 4, 5, 7, 7], then the output will be 4, as the unique numbers are [3, 4, 5, 7]. Using Set Data Structure The most straightforward approach is to use a set to track unique elements ? def count_unique_with_set(nums): unique_set = set() ...

Read More

Program to find number of string we can make where 'a' can be 'a' or 'b', and 'b' remains 'b'in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 308 Views

Suppose we have a string s with only "a" and "b". "a"s can stay "a" or turn into "b", but "b"s can not be changed. We have to find the number of unique strings that we can make. So, if the input is like s = "baab", then the output will be 4, as we can make these strings − ["baab", "babb", "bbab", "bbbb"] Approach The key insight is that only characters 'a' can be transformed. Each 'a' has 2 choices (remain 'a' or become 'b'), while 'b' characters remain unchanged. If we have n occurrences of ...

Read More

Program to check a number is ugly number or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 956 Views

An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. In other words, an ugly number can be expressed as 2i × 3j × 5k where i, j, and k are non-negative integers. So, if the input is like n = 18, then the output will be True, as 18's prime factors are 2 and 3 (18 = 2 × 32). Algorithm To solve this, we will follow these steps − If n ≤ 0, then return False (ugly numbers are positive) Create a list of factors [2, ...

Read More

Program to create one triangle stair by using stars in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 732 Views

Suppose we have a number n, we have to create a string representing stairs with n steps. Each line in the string is separated by a newline separator, forming a triangle pattern with stars. So, if the input is like n = 5, then the output will be ? * ** *** **** ***** Algorithm To solve this, we will follow these steps ? Initialize an empty string For each step from 0 to n-1: Add (n-i-1) number of spaces for ...

Read More

Program to check whether given matrix is Toeplitz Matrix or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 789 Views

A Toeplitz matrix is a square matrix where every diagonal descending from left to right has the same value. In other words, all elements along each diagonal from top-left to bottom-right are identical. So, if the input matrix is like: 7 2 6 3 7 2 5 3 7 Then the output will be True because each diagonal has consistent values. Algorithm To check if a matrix is Toeplitz, we follow these steps: For each row i except the last one, do: For each ...

Read More

Program to find the product of three elements when all are unique in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 664 Views

Sometimes we need to find the product of three numbers, but only when all numbers are unique. If any two numbers are equal, they should not contribute to the final product. So, if the input is like x = 5, y = 4, z = 2, then the output will be 40, as all three numbers are distinct so their product is 5 * 4 * 2 = 40. However, if x = 5, y = 5, z = 2, the output would be 2 since only z is unique. Algorithm To solve this, we will follow ...

Read More

Program to find final text in an editor by performing typing and backspacing in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 213 Views

Suppose we have a string that represents characters typed into an editor, where the symbol "

Read More
Showing 6351–6360 of 8,546 articles
« Prev 1 634 635 636 637 638 855 Next »
Advertisements