Yaswanth Varma

Yaswanth Varma

307 Articles Published

Articles by Yaswanth Varma

Page 2 of 31

Python program to list the difference between two lists.

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

In Python, Lists are one of the built-in data type used for storing collections of data. Python list is a sequence of comma separated items, enclosed in square brackets[]. They are flexible, easy to manipulate and widely used in various applications. In this article, we will explore to list the difference between two lists. Python provides the several built-in methods for achieving this. Using set.difference() Method The python set.difference() method is used to return the new set containing the elements that are present in the first set but not in any other sets provided as arguments. ...

Read More

Python program to communicate between parent and child process using the pipe.

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

Inter-process communication (IPC) is essential, When multiple processes need to share the data and work together. In Python, multiprocessing module provides various IPC mechanisms, Out of which one is the pipe. The pipe allows the data to be transferred from one process to another in a two-way (duplex) or one-way mode. It is useful when a parent process creates a child process and want them to exchange messages or data. Python multiprocessing.Pipe() Method The multiprocessing.Pipe() is a method in the Python multiprocessing module that return the pair of connection objects connected by a pipe. This pipe can be ...

Read More

Class or Static Variables in Python?

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

In this article we are going to learn about class or static variables on python. The class variables or static variables that are used to share across all the instances of a class. Unlike the instance variables which are specific to each object, Class variables maintain the common value for all the objects of the class. They are defined within the class but outside any instance methods, making them accessible to all the instances. These variables are used when we want to have a single shared state or value among all instance. Example 1 Let's look ...

Read More

How to import a single function from a Python module?

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

In Python, the module is a file containing Python definitions and statements. For keeping the code organized, we often write functions in separate modules and import them into main program. While importing the entire module, sometimes we only need a single function from it. Python provides a direct way to do this using the from module_name import function_name syntax. Importing sqrt() from math module In this approach, we are going to use from math module importing the sqrt to import only the sqrt function. The Python sqrt() function is used to calculate the square root of ...

Read More

How can I get a list of locally installed Python modules?

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

Python is a flexible programming language that consists of thousands of libraries and libraries. As the Python environment grows with the installations, it is important to be able to check which packages are currently installed. Whether you are debugging or documenting the environment, listing locally installed python modules can be useful. In this article, we will explore the different ways to get a list of locally installed python modules using the built-in tools and external commands. Using pip list The pip is the Python package installer and the list is tje subcommand that shows all the installed ...

Read More

Check if array can be divided into two sub-arrays such that their absolute difference is Ks in Python

Yaswanth Varma
Yaswanth Varma
Updated on 28-Aug-2025 176 Views

In this article we are going to check whether the given array can be divided into two sub-array in such a way that the absolute difference between the sums of these two sub-array is equal to the given value k. The absolute difference is nothing but the non-negative gap between two numbers, calculated as abs(sum1-sum2). In this task the split must produce two non-empty sub-array i.e. at least one element should be present in each part. Example scenarios Following are the example scenarios: Scenario 1 Input: array = [3, 1, 4, 2, 2], K = 4 ...

Read More

Check if array contains contiguous integers with duplicates allowed in Python

Yaswanth Varma
Yaswanth Varma
Updated on 28-Aug-2025 564 Views

Check for Contiguous Integers in an Array A sequence of numbers is said to be contiguous if the numbers can be arranged in such a way that each number follows the previous one without any gaps. For example,  [11, 12, 13, 14] is a contiguous sequence because there are no missing numbers between the smallest and largest values. In this article, we need to check if an array contains such contiguous integers, even when the duplicates are present. For instance, [11, 12, 13, 13, 14] should still be considered contiguous because the unique numbers are [11, 12, 13, ...

Read More

How to delete consonants from a string in Python?

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

The consonants are the alphabetic characters that is not a vowel (a, e, i, o, u). In Python, String manipulation is the common task, In this article we will explore how to delete consonants from a string using different approaches, including loops, list comprehensions and regular expression. Using Loop In this approach, we are going to declare the variable assignment with vowels in both upper and lower case and then looping through each character in the string. If the character is vowel or a non-alphabet character we will retrieve them and add to result. Example Let's ...

Read More

Check if array can be sorted with one swap in Python

Yaswanth Varma
Yaswanth Varma
Updated on 08-Aug-2025 397 Views

Sorting is a task used to organize the numbers in increasing order. Usually, we use the sorting algorithms to do this, but in most cases, the array is almost sorted, with two or three numbers in the wrong position. In such scenarios, instead of sorting the entire array, we can check if swapping just one pair of elements will make the entire array sorted. Checking if Array can be Sorted with One Swap The given task is to check if an array can be sorted with one swap in Python. i.e., given an array with distinct integers, we need ...

Read More

Check if any square (with one colored cell) can be divided into two equal parts in Python

Yaswanth Varma
Yaswanth Varma
Updated on 08-Aug-2025 249 Views

Dividing a Square into two Equal Parts In this article, we are given a square of size n*n with exactly one cell coloured. The task is to determine whether this square can be divided into two equal splits by making a single straight cut along the square, ensuring that the coloured cell lies entirely within one of the splits. Two equal splits here indicate that both parts must contain the same number of cells, which is possible if the square side length is even. In this article we are not only checking whether the split is possible but also whether the ...

Read More
Showing 11–20 of 307 articles
« Prev 1 2 3 4 5 31 Next »
Advertisements