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
Write 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 MorePython program to split and join a string?
We'll learn how to split and join a string in Python in this article. Python defines strings as a collection of characters enclosed in one, two, or three quotations. When a string is split, it is divided into smaller strings using a specific delimiter. A set of one or more characters used to define a boundary is known as a delimiter. The comma (, ), semicolon (;), tab (\t), space ( ), and pipe (|) are the most widely used delimiters. Input-Output Scenario Following is an input and its output scenario to demonstrate the split and join ...
Read MorePython program to multiply all numbers in the list?
In this article, we will explore various methods to multiply all numbers in a list in Python. A list is an ordered collection of values enclosed in square brackets, and we'll create functions that multiply each value and return the product as a single result. For example, multiplying all numbers in the list [3, 2, 6] gives us 36. Let's examine different approaches to calculate the product of all numbers in a list. Using math.prod() Function The math.prod() function, introduced in Python 3.8, provides the most straightforward way to calculate the product of all numbers in a ...
Read MorePython program to Remove and print every third from list until it becomes empty?
In this article, we will learn how to remove and print every third element from a list until it becomes empty using Python. This classic problem demonstrates circular traversal and dynamic list manipulation. Problem Understanding We need to repeatedly find and remove every third element from a list, starting from index 2 (third position). After removing an element, we continue counting from the next position in the modified list until all elements are removed. Input-Output Scenario Following is the input and its output scenario for removing and printing every third element from the list until it ...
Read MorePython Program to replace a word with asterisks in a sentence
Asterisks (*) are commonly used in text processing to censor or hide sensitive words by replacing them with symbols. In Python, we can replace specific words with asterisks using several approaches. In this article, we will explore different methods to replace a word with asterisks in a sentence. Input-Output Example Here's what word replacement with asterisks looks like − Input: Welcome to the TutorialsPoint family Output: Welcome to the TutorialsPoint ****** The word "family" is replaced with six asterisks (matching its length). Using replace() Method The replace() method searches for a ...
Read MoreMap function and Lambda expression in Python to replace characters
Sometimes we need to swap specific characters in a string. Python's map() function combined with lambda expressions provides an elegant solution for character replacement operations. Problem Statement We want to replace character a1 with character a2 and a2 with a1 simultaneously. For example ? Input string: "puporials toinp" Characters to swap: p and t Expected output: "tutorials point" Using map() and Lambda Expression The map() function applies a lambda expression to each character in the string. The lambda handles the character swapping logic ? def replaceUsingMapAndLambda(sent, a1, ...
Read MoreMap function and Dictionary in Python to sum ASCII values
In this article, we are going to learn how to use the map() function along with dictionaries to sum the ASCII values of characters in strings. The Python built-in ord() function returns the ASCII integer value of a character. Additionally, dictionaries (dict) in Python are used to store key-value pairs. We use them to associate strings with their total ASCII values, making it easy to store and retrieve results. Python map() Function The Python map() function applies a function to every item in an iterable and returns a map object. Here's the syntax ? map(function, ...
Read More