Found 10476 Articles for Python

Python program to find missing and additional values in two lists?

Yaswanth Varma
Updated on 28-Aug-2025 13:41:26

2K+ Views

In this article, we will explore how to find missing and additional values in two lists. This type of comparison is can be encountered in the real-world scenarios such as data validation or system synchronization. The task is to determine which elements are missing in one list and what unexpected elements were received. This can be achieved by using the python built-in data structures like sets that allows for easy comparison. Using set() Function The python set() function is used to used to create a new set. A set is a collection of unique elements (each ... Read More

Python program to check a sentence is a pangrams or not.

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

389 Views

Given a sentence. Our task is to check whether this sentence is pan grams or not. The logic of Pan grams checking is that words or sentences containing every letter of the alphabet at least once. To solve this problem we use set () method and list comprehension technique. Example Input: string = 'abc def ghi jkl mno pqr stu vwx yz' Output: Yes // contains all the characters from ‘a’ to ‘z’ Input: str='python program' Output: No // Does not contains all the characters from ‘a’ to 'z' Algorithm Step 1: create a string. Step 2: ... Read More

Python program to extract ‘k’ bits from a given position?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

2K+ Views

This function is use to extract k bits from pos position and returns the extracted value. Here we use python slicing technique. Example Input:: number=170 K=5 Pos=2 Output=21 Algorithm Extractionbit(no, k, pos) /*user input number is stored in variable no, extracted bit is stored in variable k and the position of bit is pos. */ Step 1 : first convert the number into its binary form using bin(). Step 2 : remove the first two character. Step 3 : then extracting k bits from starting ... Read More

Python program to reverse each word in a sentence?

Yaswanth Varma
Updated on 17-Jun-2025 17:27:38

3K+ Views

The string manipulation is the common task in the python programming, especially when working with the text based data. In this article we will explore how to reverse each word in a sentence. Generally, we reverse the entire sentence, where the both characters and the word positions are flipped, but in this task we are reversing only characters within each word while maintaining the original sequence of the words. For example if the input is "Welcome", the expected output would be "emocleW". Using Python split() Method The Python split() method is used to split all the words in ... Read More

Python program to list the difference between two lists.

Yaswanth Varma
Updated on 28-Aug-2025 13:40:29

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 print all distinct elements of a given integer array.

Yaswanth Varma
Updated on 28-Aug-2025 13:50:01

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 print a checkboard pattern of n*n using numpy.

Yaswanth Varma
Updated on 17-Jun-2025 17:37:02

612 Views

The checkboard pattern is the square grid composed of alternating 0s and 1s, arranged in a way that no two adjacent cells have the same value. It looks like the chessboard, where black and white squares alternate in every row and column. This kind of pattern is not only seen in chess or checkers, but also in image processing, graphics, and visualization, etc. In this article, we are going to learn how to print a checkboard pattern of n*n using numpy. Using Python numpy.indices() Method The numpy.indices() method is used to return the grid of indices with ... Read More

Python program to cyclically rotate an array by one

Yaswanth Varma
Updated on 17-Jun-2025 17:37:34

2K+ Views

The cyclic rotation of an array involves moving every element of the array one position forward, and the last element gets moved to the first position. For example, if the given array is [1, 2, 3, 4] then the array after one cyclic rotation is [4, 1, 2, 3]. In this article, we are going to learn how to cyclically rotate an array by one position using Python. Using Python insert() and pop() Methods The Python insert() method is used to insert or add an element at the specified index. The index value starts from zero. Following ... Read More

Python program to find common elements in three sorted arrays?

Yaswanth Varma
Updated on 20-Jun-2025 12:52:42

765 Views

The given task is to find the common element in three sorted arrays. Input Output Scenario Following is an input-output scenario - Input Arrays: array1 = [1001, 1004, 1007, 1009, 1015, 1020] array2 = [1002, 1004, 1009, 1013, 1015, 1022] array3 = [1000, 1004, 1009, 1015, 1021] Output: [1004, 1009, 1015] This is useful in multiple scenarios, for example, if we are filtering mutual friends of three different users in apps like Facebook or comparing product availability in three different e-commerce applications on a third-party website. We are filtering elements that are common in multiple ... Read More

Python program to reverse an array in groups of given size?

Yaswanth Varma
Updated on 17-Jun-2025 17:38:21

637 Views

In Python, Arrays are commonly used to store and manage collections of data. In this article, we are going to learn how to reverse an array in groups of a given size. For example, let's consider the array and a number k, which represents the size of the array. The goal is to break the array into smaller parts, each containing k elements, and then reverse the elements inside each part. If the elements left at the end are less than k, we will reverse them. Suppose the array is [1, 2, 3, 4, 5, 6] and k=3, then ... Read More

Advertisements