Found 10784 Articles for Python

Python Program to Check if any Key has all the given List Elements

Aditya Varma
Updated on 17-Aug-2023 19:24:44

69 Views

An array(list) of comma-separated values (items) enclosed in square brackets is one of the most flexible data types available in Python. The fact that a list's elements do not have to be of the same type is important. In this article, we will learn a python program to check if any key has all the given list elements. Example Assume we have taken an input dictionary and a list. We will now check whether the values of any key of the input dictionary contain given list elements using the above methods. Input inputDict = {'hello': [4, 2, 8, 1], 'tutorialspoint': ... Read More

Python Program to Check for Almost Similar Strings

Aditya Varma
Updated on 17-Aug-2023 19:02:03

115 Views

Strings in Python are sequences of characters used to represent textual data, enclosed in quotes. Checking for almost similar strings involves comparing and measuring their similarity or dissimilarity, enabling tasks like spell checking and approximate string matching using techniques such as Levenshtein distance or fuzzy matching algorithms. In this article, we will learn a Python Program to check for almost similar Strings. Demonstration Assume we have taken an input string Input Input string 1: aazmdaa Input string 2: aqqaccd k: 2 Output Checking whether both strings are similar: True In this example, ‘a’ occurs ... Read More

Python Program to Assign keys with Maximum Element Index

Aditya Varma
Updated on 17-Aug-2023 18:58:17

62 Views

In Python, an element index refers to the position of an element within a sequence, such as a list or string. It represents the location of an element, starting from 0 for the first element and incrementing by 1 for each subsequent element. Assigning keys with the maximum element index means associating unique identifiers or labels with the highest possible index value in a sequence. This approach allows for easy access and retrieval of elements based on their positions using the assigned keys. Example Assume we have taken an input dictionary. We will now find the maximum element in the ... Read More

Python Program to Append Multiple Elements in Set

Aditya Varma
Updated on 17-Aug-2023 19:04:07

397 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. Appending multiple elements to a set in Python is a common operation that involves adding multiple unique elements to an existing set. In this article, we will learn how to append multiple elements in a set in python. Example Assume we have taken an input set and input list. We will now append the input list elements to the input set ... Read More

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

162 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

125 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

79 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

201 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

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

Advertisements