Found 10476 Articles for Python

Python program to check if binary representation is palindrome?

Samual Sam
Updated on 30-Jul-2019 22:30:23

833 Views

Here we use different python inbuilt function. First we use bin() for converting number into it’s binary for, then reverse the binary form of string and compare with originals, if match then palindrome otherwise not. Example Input: 5 Output: palindrome Explanation Binary representation of 5 is 101 Reverse it and result is 101, then compare and its match with originals. So its palindrome Algorithm Palindromenumber(n) /* n is the number */ Step 1: input n Step 2: convert n into binary form. Step 3: skip the first two characters of a string. Step 4: them reverse the ... Read More

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

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

453 Views

Given the number, find length of the longest consecutive 1's in its binary representation. Example Input: n = 15 Output: 4 The binary representation of 14 is 1111. Algorithm Step 1: input the number. Step 2: use one counter variable c=0. Step 3: Count the number of iterations to reach i = 0. Step 4: This operation reduces length of every sequence of 1s by one. Example code # Python program to find # length of the longest # consecutive 1s in # binary representation of a number. def maxlength(n): # ... Read More

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

Yaswanth Varma
Updated on 28-Aug-2025 13:46:33

5K+ Views

In this article, we are going to learn about how to print the initials of a name with last name in full. For example, If we consider the applications like resumes or media references, it represents the person name using initials followed by the last name like instead of writing "Sai Vamsi Srinivas", we might write "S.V.Srinivas". This kind of formatting improves the readability and ensures the important part of the name(last name) is fully visible. Using Python split() and join() Methods The Python split() method is used to split all the words in the string by ... Read More

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

Yaswanth Varma
Updated on 28-Aug-2025 13:45:35

24K+ Views

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

SequenceMatcher in Python for Longest Common Substring.

Yaswanth Varma
Updated on 28-Aug-2025 13:44:57

1K+ Views

The SequenceMatcher class is the part of the Python difflib module. It is used to compare sequence (such as lists or strings) and finds the similarities between them. The task is to find the Longest Common Substring, i.e, the longest sequence of the characters that appears contiguously in both strings. which is different from the Longest Common Subsequence, where the characters may appear in the same order but not repeatedly. Using find_longest_match() Method The find_longest_match() method is used to find the longest matching sequence of elements between two sequences. It is the part of the Python difflib module. ... Read More

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

Yaswanth Varma
Updated on 28-Aug-2025 13:43:06

15K+ Views

In Python, Lists are one of the data types. It is sequence of comma separated items, enclosed in the square brackets []. They are widely used to store collection of item. In this article, we are going to learn about finding the maximum and minimum element's position in a list. This can be achieved by using the Python built-in functions like max(), min() and index(). Using Python max() Function The Python max() function is used to return the maximum element in the list. If the list contains the numbers, comparison is done numerically, but if the list contains strings, ... Read More

Difference between == and is operator in python.

Akshitha Mote
Updated on 17-Dec-2024 14:35:04

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. Before discussing the differences between the == and is operators in Python, let’s first understand these operators in detail. What Is the 'is' Operator? The Python is operator tests whether two variables refer to the same object in memory. If ... Read More

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

Samual Sam
Updated on 30-Jul-2019 22:30:23

145 Views

Given a 26 letter character set, here we are using a new character set. And another character set just like alphabet set (a, b, c........z), then our task is to make a relation between new character set and that alphabet set. Example New character set: qwertyuiopasdfghjklzxcvbnm Input: "wwmm" Output: bbzy Algorithm Step 1: Given a new character set and input the string to make a relation. Step 2: and the original character set also given below. Step 3: Create a dictionary, we use here map technique, we map the English character set and new given character set, ... Read More

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

Yaswanth Varma
Updated on 28-Aug-2025 13:42:15

773 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 contains 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
Updated on 30-Jul-2019 22:30:23

258 Views

Given a number n, print m multiplies of n without using any loop. Here we use recursive function. Examples Input: n = 15 Output: 15 10 5 0 5 10 15 Algorithm Step 1: Given n. Step 2: If we are moving back toward the n and we have reached there, then we are done. Step 3: If we are moving toward 0 or negative. Step 4: If m is greater, then 5, recursive function with true flag else recursive function is false. Step 5: If m is not greater than 5 then flag is false. ... Read More

Advertisements