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
Programming Articles
Page 623 of 2547
Python 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 MoreWrite a python program to count total bits in a number?
To count the total bits in a number, we convert it to binary representation using Python's bin() function. Each bit represents data as 0 or 1, making them fundamental for digital operations and data storage. Syntax The bin() function converts a number to binary format ? bin(number) # Returns binary string with '0b' prefix To count bits, we remove the '0b' prefix using slicing ? binary_bits = bin(number)[2:] # Remove '0b' prefix bit_count = len(binary_bits) # Count the bits Using the bin() Function Here's how ...
Read MoreGet emotions of images using Microsoft emotion API in Python?
Every human being has emotions like happy, sad, neutral, surprise, sorrow, and more. We can analyze these emotions in images using Python with Microsoft's Cognitive Services Emotion API. This API can detect and classify facial expressions in photographs. The Microsoft Emotion API analyzes facial expressions and returns confidence scores for different emotions including happiness, sadness, surprise, anger, fear, contempt, disgust, and neutral. Prerequisites Before using the Emotion API, you need to: Register for a Microsoft Azure account Subscribe to the Cognitive Services Emotion API Obtain your subscription key Install required Python packages: requests and json ...
Read MoreSegregate 0's and 1's in an array list using Python?
Arrays are linear data structures that store elements in contiguous memory locations. Given an array containing only 0s and 1s, we need to segregate them so all 0s appear on the left and all 1s on the right. Problem Statement The goal is to rearrange an array of 0s and 1s such that all zeros come before all ones ? Input: [0, 1, 1, 0, 0, 1, 0, 0, 0] Output: [0, 0, 0, 0, 0, 0, 1, 1, 1] Let's explore different methods to achieve this segregation in Python. Method 1: Using ...
Read MorePython program to check if there are K consecutive 1's in a binary number?
Checking for K consecutive 1's in a binary number is a common string pattern matching problem. We can solve this by creating a pattern string of K ones and checking if it exists in the binary number. Algorithm The approach involves these steps ? Take a binary string input containing only 1's and 0's Get the value K (number of consecutive 1's to find) Create a pattern string with K consecutive 1's Check if this pattern exists in the binary string Binary ...
Read More