Python Articles - Page 947 of 1048

Python program to check if both halves of the string have same set of characters.

karthikeya Boyini
Updated on 23-Jun-2020 16:01:38

268 Views

Given a string, our task is to check if both halves of the string have the same set of characters or not. To solve this problem we first split the string from the middle, so we get two halves, now we check each halves having the same set of characters or not. If the length of the string is not even then ignore the middle element and check for the rest.AlgorithmStep 1: Given a string. Step 2: Break the input string into two parts. Step 3: Then convert both parts into a dictionary using Counter(iterator) method and each dictionary contains ... Read More

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

Samual Sam
Updated on 23-Jun-2020 16:03:14

563 Views

Here n is given value which is positive number m is the number of times till which the series run. Our task is to calculate this series.AlgorithmStep 1: Input n, m; Step 2: Converting the number to string. Step 3: Initializing result as number and string. Step 4: Adding remaining terms. Step 5: Concatenating the string making n, nn, nnn... Step 6: Before adding converting back to integer. Step 7: return sum.Example Code# Python program to sum the series def sumofseries(n, m):    str1 = str(n)    sum1 = n    sumofstr1 = str(n)    for i in range(1, m): ... Read More

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

Akshitha Mote
Updated on 22-Jan-2025 13:47:27

4K+ Views

In this article, let's try to find the user's astrological sign for a given data of birth. The user input data will be compared with predefined data ranges for each zodiac sign using programming logic. For example, we can infer that the user is a Taurus if their birthdate falls between April 20 and May 20. 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, representing distinct personality traits, characteristics, and influences. These sun signs are − ... Read More

Python program to create 3D list.

Yaswanth Varma
Updated on 17-Jun-2025 16:04:10

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. For example, a matrix of images (height, width, depth). In this article, we are going to learn how to create a 3D list. As Python does not have built-in support for multi-dimensional arrays like other programming languages, but using the nested lists and loops, we can create and manipulate 3D lists. Creating a 3D List In the following example, ... Read More

Python program to remove all duplicates word from a given sentence.

Yaswanth Varma
Updated on 17-Jun-2025 15:58:09

635 Views

In this article, we are going to learn how to remove all the duplicate words from the given sentence. Generally, we will encounter situations where the sentence contains the same word repeated multiple times. These duplicate words make the text look messy and can affect further processing. Removing duplicates will help to improve the readability and ensure each word appears only once in the final sentence. Using Python split() Method The Python split() method is used to split all the words in the string using the specified separator. The separator can be a comma, full-stop, or any ... Read More

Plotting graph using seaborn in python.

Yaswanth Varma
Updated on 17-Jun-2025 17:31:26

768 Views

Seaborn is a Python visualization library built on top of matplotlib. It provides the interface for drawing statistical graphics. It simplifies the process of creating complex visualizations such as histograms, bar plots, etc. In this article, we are going to learn how to plot a graph using Seaborn in Python. To use Seaborn, we need to install it by using the command below. pip install seaborn Now, import the required libraries: import seaborn as sns import matplotlib.pyplot as plt Using seaborn.lineplot() Method The seaborn.lineplot() method is used to draw a line plot with the possibility of ... Read More

Python program to Display Hostname and IP address?

Yaswanth Varma
Updated on 28-Aug-2025 13:47:10

2K+ Views

In this article, we are going to learn how to display the hostname and IP address. Generally, the devices that connect to a network are identified by two things: Hostname: It is the name assigned to the device on a network. It helps users to identify devices in a human-readable format (e.g, mypc, desktop-pc, etc.) IP Address: It is the numerical address assigned to each device on a network, used to locate and communicate with that device. Python provides the built-in socket module for achieving this task, which provides access to various ... Read More

Python program to reverse bits of a positive integer number?

Yaswanth Varma
Updated on 19-Jun-2025 18:23:53

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. Reversing the bits of a Positive Integer Number If we reverse bits of an integer value, we are flipping the order of its binary digits such that the least important bit becomes the most important and vice versa.  The Python bin() Function: The Python bin() function accepts an integer value and converts the given integer to its binary representation. Following is the syntax of this ... Read More

Python program to check if binary representation is palindrome?

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

845 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

464 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

Advertisements