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
Articles by Vikram Chiluka
Page 7 of 22
Python Program to Get word frequency in percentage
In this article, we will learn how to get word frequency in percentage in python. Assume we have taken an input list of strings. We will now find the percentage of each word in the given input list of strings. Formula (Occurrence of X word / Total words) * 100 Methods Used Using sum(), Counter(), join() and split() functions Using join(), split() and count() functions Using countOf() function from operator module. Method 1: Using sum(), Counter(), join() and split() functions join() is a string function in Python that is used to join elements of a sequence ...
Read MorePython program to find the sum of dictionary keys
In this article, we will learn a python program to find the sum of dictionary keys. Methods Used The following are the various methods to accomplish this task − Using for loop Using dict.keys() and sum() functions Using reduce() function Using items() function Example Assume we have taken an input dictionary containing some random key-value pairs. We will now find the sum of all the keys of an input dictionary using the above methods. Input inputDict = {4: 10, 1: 30, 10: 50, 2: 70, 8: 90} Output Sum of keys of an input dictionary: 25 ...
Read MorePython program to find the sum of Characters ascii values in String List
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 MorePython Program to Extract Strings with a digit
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 MorePython program to count the number of spaces in string
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 MorePython Program to Count of Words with specific letter
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 MorePython Program to Alternate list elements as key-value pairs
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 MoreHow to Common keys in list and dictionary using Python
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 MoreFind the difference of the sum of list elements that are missing from Matrix and vice versa in python
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 MoreCase-insensitive string replacement using Python Program
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