Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Print m multiplies of n without using any loop in Python.
Given a number n, we can print m multiples of a step value without using any loop by implementing a recursive function. This approach uses function calls to simulate iteration. Problem Statement We need to print numbers starting from n, decreasing by a step value until we reach 0 or negative, then increasing back to the original number. Example Input: n = 15, step = 5 Output: 15 10 5 0 5 10 15 Algorithm The recursive approach works as follows: Start with the given number n and a flag ...
Read MorePython program to find missing and additional values in two lists?
In this article, we will explore how to find missing and additional values in two lists. This type of comparison is commonly encountered in real-world scenarios such as data validation, system synchronization, and database reconciliation. The task is to determine which elements are missing in one list and what unexpected elements were received. This can be achieved by using Python's built-in data structures like sets that allow for efficient comparison operations. Understanding the Problem When comparing two lists, we need to identify: Missing values: Elements present in the first list but absent in the second list ...
Read MorePython program to check a sentence is a pangrams or not.
A pangram is a sentence that contains every letter of the alphabet at least once. For example, "The quick brown fox jumps over the lazy dog" is a famous pangram. We can check if a sentence is a pangram using Python's set() operations. Example Input and Output Input: string = 'abc def ghi jkl mno pqr stu vwx yz' Output: Yes // contains all the characters from 'a' to 'z' Input: string = 'python program' Output: No // Does not contain all the characters from 'a' to 'z' Algorithm Here's the step-by-step approach ...
Read MorePython program to extract 'k' bits from a given position?
Bit extraction involves extracting a specific number of bits from a given position in a number's binary representation. This is useful in low-level programming, cryptography, and data manipulation tasks. Understanding the Problem Given a number, we need to extract 'k' consecutive bits starting from a specific position 'pos' (counted from the right, starting at 0). The extracted bits are then converted back to decimal. Example Input: number=170, k=5, pos=2 Output: 21 Binary of 170: 10101010 Position 2 from right, extract 5 bits: 01010 Decimal value: 21 Algorithm The ...
Read MorePython program to list the difference between two lists.
In Python, Lists are one of the built-in data types used for storing collections of data. Python lists are sequences 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 different methods to find the difference between two lists. Python provides several built-in approaches for achieving this. Using set.difference() Method The Python set.difference() method returns a new set containing elements that are present in the first set but not in any other sets provided as arguments. Syntax set.difference(*others) ...
Read MorePython program to print all distinct elements of a given integer array.
The distinct elements are the values that appear only once or uniquely in an array. When working with arrays, we often encounter repeated or duplicate values. In this article, we will explore different methods to print all distinct elements of a given integer array. Identifying and printing these distinct elements is a common task to avoid unexpected results. This can be achieved using Python built-in tools like sets, dictionaries, and loops. Using Python set() Function In this approach, we use the Python set() function, which automatically removes all duplicate values from the list because a set only ...
Read MorePython program to print a checkboard pattern of n*n using numpy.
The checkboard pattern is a square grid composed of alternating 0s and 1s, arranged in a way that no two adjacent cells have the same value. It looks like a chessboard, where black and white squares alternate in every row and column. This pattern is commonly used in chess, checkers, image processing, graphics, and visualization. In this article, we'll learn how to create a checkboard pattern of n×n using NumPy. Using numpy.indices() Method The numpy.indices() method returns a grid of indices with the given shape. It creates coordinate matrices from coordinate vectors that we can use to ...
Read MorePython program to communicate between parent and child process using the pipe.
Inter-process communication (IPC) is essential when multiple processes need to share data and work together. In Python, the multiprocessing module provides various IPC mechanisms, one of which is the pipe. A pipe allows data to be transferred between processes in either two-way (duplex) or one-way mode. It is particularly useful when a parent process creates a child process and they need to exchange messages or data. Python multiprocessing.Pipe() Method The multiprocessing.Pipe() method returns a pair of connection objects connected by a pipe. This pipe enables sending and receiving data between two processes. Syntax multiprocessing.Pipe(duplex=True) ...
Read MorePython program to check the validity of a Password?
Password validation is crucial for application security. A strong password should meet specific criteria including minimum length, mixed case letters, numbers, and special characters. Python's re module provides regular expressions to check these requirements efficiently. Password Validation Rules A valid password must satisfy the following criteria − Minimum 8 characters long At least one lowercase letter (a-z) At least one uppercase letter (A-Z) At least one digit (0-9) At least one special character (_ @ $) No whitespace characters Algorithm Step 1: Import re module for regular expressions Step 2: Get password ...
Read MorePython program to iterate over multiple lists simultaneously?
In this article, we are going to learn how to iterate over multiple lists simultaneously. This is useful when the lists contain related data. For example, one list stores names, another stores ages, and a third stores grades. By iterating over these lists simultaneously, we can access the complete information for each item. Using zip() Function The Python zip() function is a built-in function used to combine elements from two or more iterable objects (such as lists, tuples, etc) and returns an iterator. The resultant iterator contains tuples where the ith tuple contains the ith element from each ...
Read More