Found 31499 Articles for Programming

Python program to find the sum of Characters ascii values in String List

Vikram Chiluka
Updated on 27-Jan-2023 11:47:25
In this article, we will learn a python program to find the sum of characters' ASCII values in a list of strings. Methods Used The following are the various methods to accomplish this task − Using for Loop, + operator, ord() function Using list Comprehension, sum(), ord() functions Example Assume we have taken an input list containing string elements. We will find the @@ Input Input List: ['hello', 'tutorialspoint', 'python', 'platform'] Output [52, 209, 98, 101] Here, The ASCII values of all the characters of each list element like hello is 8+5+12+12+15 = 52 where ASCII ... Read More

Python Program to Extract Strings with a digit

Vikram Chiluka
Updated on 27-Jan-2023 11:45:19
In this article, we will learn how to extract strings with a digit in python. Methods Used The following are the various methods to accomplish this task − Using list comprehension, any() and isdigit() functions Using any(), filter() and lambda functions Without using any built-in functions Using ord() function Example Assume we have taken an input list containing strings. We will now extract strings containing a digit in an input list using the above methods. Input inputList = ['hello562', 'tutorialspoint', 'python20', 'codes', '100'] Output List of Strings containing any digits: ['hello562', 'python20', '100'] In the above ... Read More

Python program to count the number of spaces in string

Vikram Chiluka
Updated on 27-Jan-2023 11:43:40
In this article, we will a python program to count the number of spaces in a string. Methods Used The following are the various methods to accomplish this task − Using for loop (with indexing) Using count() function Using isspace() function Using Counter() function Using countOf() function of the operator module Assume we have taken an input string. we will now count the number of spaces in an input string above methods. Method 1: Using for loop (with indexing) Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task –. Create a function ... Read More

Python Program to Count of Words with specific letter

Vikram Chiluka
Updated on 27-Jan-2023 11:42:13
In this article, we will learn how to count Words with a specific letter in a string in python. Methods Used The following are the various methods to accomplish this task − Using list comprehension, len() & split() functions Using split() & find() functions Using split(), replace() & len() functions Using Counter() function Example Assume we have taken an input string and some random character. We will now count the words that contain the given input character in an input string. Input inputString = 'hello tutorialspoint python codes' inputChar = "p" Output Count of words containing the ... Read More

Python program to concatenate every elements across lists

Vikram Chiluka
Updated on 27-Jan-2023 11:38:40
In this article, we will learn a Python program to concatenate every element across lists. Methods Used The following are the various methods to accomplish this task − Using the List Comprehension and String Concatenation Using itertools.product() Function Example Assume we have taken two input lists. We will now concatenate every element across the given two lists Input inputList1 = ["hello", "tutorialspoint", "python"] inputList2 = ["coding", "articles"] Output Resultant paired combinations list: ['hello coding', 'hello articles', 'tutorialspoint coding', 'tutorialspoint articles', 'python coding', 'python articles'] Method 1: Using the List Comprehension and String Concatenation List Comprehension When ... Read More

Python Program to Capitalize repeated characters in a string

Vikram Chiluka
Updated on 27-Jan-2023 11:37:38
In this article, we will learn how to capitalize repeated characters in a string in python. Methods Used The following are the various methods to accomplish this task - Using Dictionary Hashing Using count() Function Using replace() and len() functions Using Counter() function Example Assume we have taken an input string containing some random text. We will now convert the repeated characters in an input string into uppercase using the above methods. Input inputString = 'hello tutorialspoint' Output heLLO TuTOrIaLspOInT In the above input string, the characters l, o, t, i are repeated. Hence they are ... Read More

Python Program to Alternate list elements as key-value pairs

Vikram Chiluka
Updated on 27-Jan-2023 11:31:42
In this article, we will learn how to get alternate list elements as key-value pairs in python. Assume we have taken an input list containing integers. We will now Methods Used The following are the various methods used to accomplish this task − Using for loop Using dictionary comprehension and list slicing Example Assume we have taken an input list. We will now print alternate list elements as key-value pairs. Input inputList = [20, 13, 5, 2, 6, 8, 18, 3] Output Dictionary with alternate list elements as key-value pairs: {13: 2, 2: 8, 8: 3, 20: ... Read More

How to Common keys in list and dictionary using Python

Vikram Chiluka
Updated on 27-Jan-2023 11:30:17
In this article, we will learn how to find common keys in a list and dictionary in python. Methods Used The following are the various methods to accomplish this task − Using the ‘in’ operator and List Comprehension Using set(), intersection() functions Using keys() function & in operator Using the Counter() function Example Assume we have taken an input dictionary and list. We will find the common elements in the input list and keys of a dictionary using the above methods. Input inputDict = {"hello": 2, "all": 4, "welcome": 6, "to": 8, "tutorialspoint": 10} inputList = ["hello", "tutorialspoint", ... Read More

Find the difference of the sum of list elements that are missing from Matrix and vice versa in python

Vikram Chiluka
Updated on 27-Jan-2023 11:26:23
In this article, we will learn how to find the difference of the sum of list elements that are missing from Matrix and vice versa. Methods Used The following are the various methods to accomplish this task − Using for loop & from_iterable() function Using sum() & from_iterable() functions Using the Counter() function Example Assume we have taken an input matrix and a target list. We will now find the difference of the sum of list elements that are missing from Matrix and vice versa. Input inputMatrix = [[6, 3, 2], [5, 4, 1], [10, 8, 1], [15, ... Read More

Case-insensitive string replacement using Python Program

Vikram Chiluka
Updated on 27-Jan-2023 11:20:58
In this article, we will learn Case insensitive string replacement in python. Methods Used The following are the various methods to accomplish this task − Using re.IGNORECASE, re.escape(), re.sub() Using re.sub(), lambda, re.escape() functions Using split(), lower() & replace() functions Using split(), list() and join() functions Method 1: Using re.IGNORECASE, re.escape(), re.sub() re.compile() function A regular expression pattern can be combined with pattern objects, which can then be used for pattern matching. This function also allows searching for a pattern again without rewriting it. Syntax re.compile(pattern, repl, string) re.sub() function The string with replaced ... Read More
Advertisements