Found 10784 Articles for Python

Matrix and linear Algebra calculations in Python

Vikram Chiluka
Updated on 01-Feb-2023 20:10:57

784 Views

In this article, we will learn Matrix and linear Algebra calculations in Python such as matrix multiplication, finding determinants, solving linear equations, etc. A matrix object from the NumPy library can be used for this. When it comes to calculation, matrices are relatively comparable to the array objects Linear Algebra is a huge topic that is outside of this article. However, NumPy is an excellent library to start if you need to manipulate matrices and vectors. Methods Used Finding Transpose of a Matrix Using Numpy Finding Inverse of a Matrix Using Numpy Multiplying Matrix with a Vector ... Read More

Python program to Uppercase selective indices

Vikram Chiluka
Updated on 27-Jan-2023 12:22:26

1K+ Views

In this article, we will learn a python program to convert the string elements to uppercase for the given selective indices. Methods Used The following are the various methods to accomplish this task − Using For Loop and upper() function Using List Comprehension Using index() & join() functions Example Assume we have taken an input string and a list containing index values. We will now convert the characters of an input string to uppercase at those given indices and print the resultant string. Input inputString = 'hello tutorialspoint python' indexList = [0, 6, 8, 10, 15, ... Read More

Python Program to Test if string contains element from list

Vikram Chiluka
Updated on 27-Jan-2023 12:28:22

985 Views

In this article, we will learn how to check if a string contains an element from a list in python. Methods Used Using Nested For Loops Using List Comprehension Using any() function Using the find() function Example Assume we have taken an input string and input list. We will now check whether the input string contains at least any one input list element. Input inputString = "tutorialspoint is a best learning platform for coding" inputList = ['hello', 'tutorialspoint', 'python'] Output YES, the string contains elements from the input list In the above example, the ... Read More

Python Program to Test if any set element exists in List

Vikram Chiluka
Updated on 27-Jan-2023 12:19:16

2K+ Views

In this article, we will learn how to check if any set element exists in the list in python. Methods Used Using any() function Using Bitwise & operator Using Counter(), filter() and lambda functions Example Assume we have taken an input set and input list. We will now check whether any input set element exists in the input list using the above methods. Input inputSet = {4, 8, 1, 3, 5, 7} inputList = [7, 15, 20] Output Checking whether any set element present in the input list: True In the above example, 7 exists ... Read More

Python Program to Subtract K from each digit

Ranbir Kapoor
Updated on 31-Jul-2023 12:39:55

65 Views

In this article, we will learn a python program to subtract K from each digit in a list. Assume we have taken an input list containing numbers and K value. We will now subtract k from each digit of a list element and print the resultant list using the below methods. Example Let inputList = [1034, 356, 2145, 6712, 8671] Given input k value = 3 Now we consider 1st element i.e, 1034 Subtract 3 from each digit of 1034 i.e, 1-3 =-2. So, it is ceiled to 0 0-3 = -3. So, it is ceiled to ... Read More

Python Program to Split a String by Custom Lengths

Vikram Chiluka
Updated on 27-Jan-2023 12:08:51

2K+ Views

In this article, we will learn how to split a string by custom lengths in python. Methods Used The following are the various methods to accomplish this task − Using for loop and slicing Using List Comprehension, join() and next() functions Example Assume we have taken an input string and custom lengths list. We will now split an input string by input custom lengths using the above methods. Input inputString = 'hitutorialspoint' customLengths = [4, 1, 6, 5] Output ['hitu', 't', 'orials', 'point'] In the above example, firstly the input list is split based on the ... Read More

Python Program to Sort A List Of Names By Last Name

Vikram Chiluka
Updated on 27-Jan-2023 12:05:17

1K+ Views

In this article, we will learn a python program to sort a list of names by last name. Methods Used Using lambda and sorted() functions Using lambda and sort() functions Example Assume we have taken an input list containing string elements. We will now sort the list elements in ascending order of the last names alphabetically using the above methods. Input Input List: ['sachin tendulkar', 'suresh raina', 'hardik pandya'] Output Input List after sorting by last names: ['hardik pandya', 'suresh raina', 'sachin tendulkar'] The last names of input list elements are tendulkar, raina, pandya i.e t, ... Read More

Python Program to Replace all words except the given word

Vikram Chiluka
Updated on 27-Jan-2023 12:03:24

283 Views

In this article, we will learn how to replace all words except the given word in a string in python. Methods Used The following are the various methods to accomplish this task − Using For Loop, split() & join() Functions Using List Comprehension Example Assume we have taken an input string, input word, and the input character with which to be replaced. We will now replace all the words in an input string with the given input replace character expect the given word using the above methods. Input inputString = 'hello tutorialspoint python codes' inputWord = "tutorialspoint" ... Read More

Python Program to Remove numbers with repeating digits

Vikram Chiluka
Updated on 27-Jan-2023 12:02:20

708 Views

In this article, we will learn how to remove numbers with repeating digits in python. Methods Used The following are the various methods to accomplish this task − Using list comprehension and set() function Using re module Using the Counter() function Example Assume we have taken an input list containing numbers. We will now remove all the numbers from the list containing repeating digits and return the resultant list using the above-mentioned methods. Input inputList = [3352, 8135, 661, 7893, 99] Output [8135, 7893] In the above input list, in the 1st element 3352, 3 ... Read More

Python program to remove K length words in String

Vikram Chiluka
Updated on 27-Jan-2023 12:00:36

419 Views

In this article, we will learn a python program to remove K-length words in String. Methods Used The following are the various methods to accomplish this task − Using split(), join(), len() and list comprehension Using filter(), lambda(), split() and len() functions Using split(), join(), remove() and len() functions Example Assume we have taken an input string and k length. We will now remove all the given k-length words from the input string using the above methods. Input inputString = "hello tutorialspoint python codes" k_length = 5 Output Resultant string after removing 5 length words: tutorialspoint ... Read More

Advertisements