Python Articles

Page 729 of 855

Python program to reverse bits of a positive integer number?

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

In Python, every number is represented internally as a sequence of binary digits, known as bits. In this article, we are going to learn how to reverse the bits of a positive integer number using different approaches. What is Bit Reversal? When we reverse bits of an integer value, we flip the order of its binary digits such that the least significant bit becomes the most significant bit and vice versa. Bit Reversal Example Original: 10 1 0 ...

Read More

Python program to find the length of the largest consecutive 1's in Binary Representation of a given string.

Arjun Thakur
Arjun Thakur
Updated on 24-Mar-2026 523 Views

Given a number, we need to find the length of the longest consecutive 1's in its binary representation. This problem can be solved using bit manipulation techniques. Example Input: n = 15 Output: 4 The binary representation of 15 is 1111. Algorithm The algorithm uses bit manipulation to count consecutive 1's: Step 1: Input the number Step 2: Use a counter variable to track iterations Step 3: Apply bitwise AND with left-shifted number Step 4: This reduces each sequence of 1's by one in each iteration Step 5: Count iterations until the number becomes 0 Using Bit Manipulation This method uses the property that n & (n

Read More

Python program to print the initials of a name with last name in full?

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

In this article, we are going to learn how to print the initials of a name with last name in full. For example, in applications like resumes or media references, instead of writing "Sai Vamsi Srinivas", we might write "S.V. Srinivas". This kind of formatting improves readability and ensures the important part of the name (last name) is fully visible. Using Python split() and join() Methods The Python split() method splits all words in a string using a specified separator. The separator can be a space, comma, or any other character. Following is the syntax ? ...

Read More

Python program to split the even and odd elements into two different lists.

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

In this article, we are going to learn about splitting the even and odd elements into two different lists. This involves looping through each element in a list and checking whether it is divisible by 2. Even numbers are those that give the remainder '0' when divided by 2, while the odd numbers leave a remainder '1'. Using append() Method The Python append() method is used to add a new object to a list. It accepts an object as an argument and inserts it at the end of the existing list. Syntax list.append(obj) ...

Read More

SequenceMatcher in Python for Longest Common Substring.

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

The SequenceMatcher class is part of Python's difflib module. It compares sequences (such as lists or strings) and finds similarities between them. The task is to find the Longest Common Substring — the longest sequence of characters that appears contiguously in both strings. This is different from the Longest Common Subsequence, where characters may appear in the same order but not necessarily contiguous. Using find_longest_match() Method The find_longest_match() method finds the longest matching sequence of elements between two sequences. It returns a Match object with three attributes: a (start position in first sequence), b (start position in ...

Read More

Python program to find Maximum and minimum element’s position in a list?

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

In Python, Lists are one of the most versatile data types. They store sequences of comma-separated items enclosed in square brackets []. Finding the maximum and minimum element positions is a common task that can be achieved using Python's built-in functions max(), min(), and index(). Understanding the Required Functions max() Function The max() function returns the largest element in a list. For numbers, comparison is done numerically; for strings, comparison is done alphabetically. max(list) min() Function The min() function returns the smallest element in a list. Like max(), it compares numbers numerically ...

Read More

Difference between == and is operator in python.

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

In Python, the == and is operators are used for comparison, but they serve different purposes. The == operator checks for equality of values, which means it evaluates whether the values of two objects are the same. On the other hand, the is operator checks for identity, meaning it determines whether two variables point to the same object in memory. What Is the 'is' Operator? The Python is operator tests whether two variables refer to the same object in memory. If the variables refer to the same memory location, it returns True; otherwise, it returns False. This operator ...

Read More

Zip function in Python to change to a new character set.

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

The zip() function in Python can be used to create a mapping between two character sets. This is useful when you want to translate text from one character encoding to another, such as converting from a custom character set back to the standard alphabet. Problem Statement Given a custom 26-letter character set and the standard alphabet, we need to create a mapping to translate strings from the custom set back to normal letters. Custom character set: qwertyuiopasdfghjklzxcvbnm Standard alphabet: abcdefghijklmnopqrstuvwxyz Input: "wwmm" Output: "bbzy" Algorithm Define the custom character ...

Read More

Python program to check if binary representation of two numbers are anagram.

Yaswanth Varma
Yaswanth Varma
Updated on 24-Mar-2026 871 Views

The binary numbers are the basis of how data is stored, processed and transferred. Every integer is internally represented by using a sequence of bits (combination of 0s and 1s). In this article, we will learn how to check if binary representation of two numbers are anagram. Two numbers are said to be binary anagrams if their binary representations contain the same number of 1s and 0s. For example, the number 12 in binary is 1100 and the number 10 in binary is 1010, both have two 0s and two 1s, making them binary anagrams. Using collections.Counter() Class ...

Read More

Print m multiplies of n without using any loop in Python.

karthikeya Boyini
karthikeya Boyini
Updated on 24-Mar-2026 322 Views

Given a number n, we can print m multiples of a step value without using any loop by implementing a recursive function. This approach uses function calls to simulate iteration. Problem Statement We need to print numbers starting from n, decreasing by a step value until we reach 0 or negative, then increasing back to the original number. Example Input: n = 15, step = 5 Output: 15 10 5 0 5 10 15 Algorithm The recursive approach works as follows: Start with the given number n and a flag ...

Read More
Showing 7281–7290 of 8,546 articles
« Prev 1 727 728 729 730 731 855 Next »
Advertisements