Python Articles

Page 3 of 852

Program to find length of longest anagram subsequence in Python

Niharikaa Aitam
Niharikaa Aitam
Updated on 01-Sep-2025 414 Views

In Python, a string is immutable data structure in which sequence of characters are enclosed in double("") or single quotes(''). In some cases, we need to find the length of the longest subsequence of characters that can be rearranged to form a palindrome. This type of subsequence is referred to as a palindromic anagram subsequence. To solve this, we need to count how many characters appear an even number of times and at most one character can appear an odd number of times. An anagram is a word or phrase formed by rearranging the letters of another word or phrase ...

Read More

Program to return number of smaller elements at right of the given list in Python

Niharikaa Aitam
Niharikaa Aitam
Updated on 01-Sep-2025 457 Views

In Python, a list is a ordered and mutable data structure where elements are enclosed in square braces []. In some scenarios, we may need to count how many elements to the right of each element in the list are smaller than it. Using Binary Search with bisect_left() Function The bisect_left() Function of the bisect method is used locate the insertion point for an element in a sorted list to maintain the list's sorted order. The insertion point returned by bisect_left() is the index where the element can be inserted without violating the sort order by placing it before any ...

Read More

Program to find which element occurs exactly once in Python

Niharikaa Aitam
Niharikaa Aitam
Updated on 01-Sep-2025 568 Views

In Python, datastructures such as string, list etc., may contain duplicates of a value. In few scenarios, we may need to find which element appears only once while all others elements appear multiple times. Let's go through different methods to find which element occurs exactly once in Python. Using Bitwise XOR The XOR is abbrivated as Exclusive OR is a bitwise operator which returns 1 if the corresponding bits of two operands are different otherwise, it returns 0 if they are same. In Python, we can use the ^ between two operands to perform Exclusive OR operation. Example Following is ...

Read More

Locating Modules in Python

gireesha Devara
gireesha Devara
Updated on 01-Sep-2025 2K+ Views

Locating modules in Python refers to the process of how Python finds and loads a module into our current program when we are trying to import it. Python's standard library comes with a large number of modules that we can use in our programs with the import statement. Locating Modules in Python When you write an import statement like import mymodule, the Python interpreter searches for the module in the following sequences: The current directory: Python first checks the directory of the current script. PYTHONPATH Environment Variable: If the module isn't ...

Read More

Python program to print all distinct elements of a given integer array.

Yaswanth Varma
Yaswanth Varma
Updated on 28-Aug-2025 1K+ Views

The distinct elements are the values that appears only once or uniquely in the array. When working with the array we will come across the repeated or duplicate values. In this article, we are going to print all the distinct elements of a given array. Identifying and printing these distinct elements is a common task to avoid the unexpected results. This can be achieved by using the Python built-in tools like sets and dictionaries. Using Python set() Function In this approach we are using Python set() function, which removes all the duplicate value from the list because a ...

Read More

Python program to Display Hostname and IP address?

Yaswanth Varma
Yaswanth Varma
Updated on 28-Aug-2025 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 print the initials of a name with last name in full?

Yaswanth Varma
Yaswanth Varma
Updated on 28-Aug-2025 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
Yaswanth Varma
Updated on 28-Aug-2025 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
Yaswanth Varma
Updated on 28-Aug-2025 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
Yaswanth Varma
Updated on 28-Aug-2025 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
Showing 21–30 of 8,519 articles
« Prev 1 2 3 4 5 852 Next »
Advertisements