Found 34494 Articles for Programming

Python Program to Accessing K Element in set without Deletion

Aditya Varma
Updated on 17-Aug-2023 18:52:14

42 Views

In Python, a set is an unordered collection of unique elements, represented by {}. It allows efficient membership testing and eliminates duplicate values, making it useful for tasks such as removing duplicates or checking for common elements between sets. In this article, we will learn how to access the K element in a set without deletion in python. Example Assume we have taken an input set and K element. We will now find the index of that K element in an input set using the above methods. Input inputSet = {3, 9, 5, 1, 2, 8} k=5 Output The ... Read More

How to Reverse String Consonants without Affecting other Elements in Python

Aditya Varma
Updated on 17-Aug-2023 18:48:31

163 Views

String consonants refer to the non-vowel sounds produced when pronouncing a string of characters or letters. In this article, we are going to study how to reverse only the consonants in a string without affecting the position of other elements using the following 2 methods in Python: Using append() and join() functions Using pop() function and string concatenation Example Before Reversing : tutorialspoint After Reversing: tunopiaslroitt Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task –. The function checkConsonant(char) is defined to check if a character is a consonant ... Read More

How to Check if a given Matrix is a Markov Matrix using Python?

Aditya Varma
Updated on 17-Aug-2023 18:45:04

127 Views

In this article we are going to learn how to check whether the input matrix is a Markov Matrix using nested for loops and sum() function. Before that let us understand what is Markov Matrix with an example? The matrix is said to be a Markov matrix if the sum of each row is equal to 1. Example [ [ 0, 1, 0 ], [ 0, 0.3, 0.7 ], [ 0, 0, 1 ]] In the above example, the sum of each row is 1. Hence the above matrix is an example of a Markov ... Read More

How to check Idempotent Matrix in Python?

Aditya Varma
Updated on 17-Aug-2023 18:41:56

80 Views

If a matrix produces the same matrix when multiplied by itself, it is said to be an idempotent matrix. If and only if M * M = M, the matrix M is considered to be an idempotent matrix. Where M is a square matrix in the idempotent matrix. Matrix M: 1 0 0 0 1 0 0 0 0 Performing M*M 1 0 0 * 1 0 0 = 1 0 0 0 1 0 0 1 0 ... Read More

Check Horizontal and Vertical Symmetry in the Binary Matrix using Python

Aditya Varma
Updated on 17-Aug-2023 18:39:16

203 Views

A binary matrix is a rectangular grid in which each element is either 0 or 1, indicating true or false states. It is widely employed to represent relationships, connectivity, and patterns across various disciplines Assume we have taken a 2D binary input matrix containing N rows and M columns. T. We will now check whether the input matrix is horizontal or vertically symmetric or both using the below method. If the first row matches the last row, the second row matches the second last row, and so on, the matrix is said to be horizontally symmetric. If the first ... Read More

Java Program for Arithmetic Operations Between BigDecimal and Primitive Data Types

Mr. Satyabrata
Updated on 17-Aug-2023 17:24:04

118 Views

BigDecimal is a class in Java's java.math package that provides arbitrary-precision decimal arithmetic. It allows precise decimal calculations without the loss of precision that can occur with floating-point arithmetic. BigDecimal objects are immutable, so any arithmetic operation on them creates a new object with the result of the operation. Primitive data types in Java are the basic building blocks of data in the language. They include int, double, Boolean, char, and others, and represent simple values like integers, floating-point numbers, and boolean values. They are stored directly in memory and are not objects, so they have lower memory overhead ... Read More

Python - K difference index Pairing in List

Tapas Kumar Ghosh
Updated on 17-Aug-2023 18:23:22

75 Views

The K is the special number that set the sum of the difference values starting with 0th index. For example, if k = 3 it means the 0th index added with K and finds the exact pairs. In Python, we have some built-in functions such as str(), len(), and append() will be used to solve the K difference index pairing in list. Let’s take an example of list. The given list, [“A”, “B”, “C”, “D”, “E”, “F”] Then the K value set to 1 The final output pair the index as [“AC”, “BD”, “CE”, ... Read More

Find Difference Between Sum of All Rows and All Columns in Java

Mr. Satyabrata
Updated on 17-Aug-2023 17:21:36

81 Views

In Java, a matrix can be represented using a two-dimensional array. Matrices are used for storing and manipulating data that have a tabular structure. Matrices have several properties and operations associated with them, such as addition, subtraction, multiplication, transposition, and determinant calculation. As per the problem statement we have to add sum of all individual rows and columns. Then we need to perform the difference between these added rows and columns and display the result. Let's start! For instance Suppose the original matrix is: {4, 2, 1}, {3, 5, 6}, {8, 9, 7} After performing ... Read More

Check if the Sum of Digits of a Number N Divides It

Tapas Kumar Ghosh
Updated on 17-Aug-2023 18:19:17

112 Views

The N number is the special number of integer type that calculates the individual digit of sum. So, this sum will be divisible by its own number. Let’s take an example of this. The given integer number, N = 36 The sum of each digit, 3 + 6 = 9 Therefore, 36 is successfully divisible by 9 and it verifies for N divides it. Algorithm The following steps are- Step 1: We will start the program by mentioning the header file iostream. Step 2: Common Matches:- Then used the function definition digit_sum() that accepts the parameter a variable n ... Read More

How to Sort a Pandas DataFrame by Date?

Tapas Kumar Ghosh
Updated on 17-Aug-2023 18:16:25

2K+ Views

Python’s Pandas DataFrame defines the two-dimensional structure that consists of rows and columns. The main feature of pandas is an easier way of handing the given data. In Python, we have some in-built functions such as to_datetime(), sorted(), lambda, and, sort_value() will be Sort a Pandas DataFrame by Date. Syntax The following syntax is used in the examples- to_datetime() The to_datetime() is an in-built function in Python that convert string dates into date-time objects. sorted() The built-in function sorted() of Python states that the list can be sort as specified iterable objects. lambda This lambda function in ... Read More

Advertisements