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 by Sarika Singh
Page 3 of 15
Python program to sort a tuple by its float element
This article demonstrates how to sort a list of tuples by their float elements in Python. We'll explore three different approaches: using sorted(), using sort(), and implementing bubble sort manually. Input-Output Scenarios The following scenarios show how tuples are sorted by their float elements in descending order ? Scenario 1 Input: data = [('Dengue', '54.865'), ('Malaria', '345.743'), ('Corona', '456.864'), ('Typhoid', '35.285'), ('Jaundice', '83.367')] Output: [('Corona', '456.864'), ('Malaria', '345.743'), ('Jaundice', '83.367'), ('Dengue', '54.865'), ('Typhoid', '35.285')] Scenario 2 Input: data = [('638', '54.865'), ('932', '345.743'), ('256', '456.864'), ('843', '35.285'), ('246', '83.367')] Output: [('256', ...
Read MorePython Program to find mirror characters in a string
This article teaches you how to write a Python program to find mirror characters in a string. A mirror character is the alphabetically opposite character − 'a' mirrors to 'z', 'b' to 'y', and so on. Understanding Mirror Characters Mirror characters are pairs of letters that are equidistant from both ends of the alphabet. For example: 'a' (1st letter) mirrors to 'z' (26th letter) 'b' (2nd letter) mirrors to 'y' (25th letter) 'c' (3rd letter) mirrors to 'x' (24th letter) Input-Output Example Given a string and a position, we mirror characters from that ...
Read MorePython Program to check if two given matrices are identical
Matrix refers to a collection of numbers arranged in rows and columns to form a rectangular array. The numbers make up the matrix's entries, or elements. We need to create a Python function to determine whether two given matrices are identical. In other words, we say that two matrices are identical if all of the elements in their respective places are the same. Identical Matrices Two matrices are only considered equal if and when they meet the requirements listed below − There should be an equal number of rows and columns ...
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 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 MoreHow to get the class name of an instance in Python?
In Python object-oriented programming, getting the class name of an instance is a common requirement. Python provides several approaches to retrieve the class name from any object or instance. Using __class__.__name__ The most straightforward method uses the __class__ attribute combined with __name__ to get the class name ? class Animal: def __init__(self, name): self.name = name lion = Animal("Lion") print(lion.__class__.__name__) Animal The __class__ attribute returns the class object, while __name__ gives the actual class name as a string. ...
Read MoreExplain Python class method chaining
In object-oriented programming, method chaining is a programming technique where multiple method calls are linked together in a single expression. Each method returns an object (typically self), allowing the next method to be called on the result. Method chaining provides two key benefits ? Reduced code length − No need to create intermediate variables for each step Improved readability − Operations flow sequentially in a clear, logical order How Method Chaining Works For method chaining to work, each method must return an object (usually self) so the next method can be called on it. ...
Read More