Server Side Programming Articles

Page 151 of 2109

Python Program to Join strings by multiple delimiters

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 578 Views

In this article, we will learn how to join strings by multiple delimiters in Python. This technique is useful when you need to create multiple variations of joined strings using different separators. Methods Used The following are the various methods to accomplish this task ? Using List Comprehension and "+" Operator Using List Comprehension and join() Function Example Overview Assume we have taken two input strings and a multiple delimiters list. We will now join both the input strings with the given input delimiters and return a resultant list ? Input ...

Read More

Python Program to Get word frequency in percentage

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 872 Views

In this article, we will learn how to calculate word frequency as percentages in Python. Given a list of strings, we'll find what percentage each word represents of the total word count. Formula Word Frequency (%) = (Occurrence of word / Total words) × 100 Method 1: Using Counter() from collections The Counter() function counts hashable objects and returns a dictionary-like object. The join() function connects sequence elements into a single string ? from collections import Counter # Input list of strings input_strings = ["hello tutorialspoint", "python codes", "tutorialspoint for python", ...

Read More

Python program to find the sum of dictionary keys

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 4K+ Views

In this article, we will learn different Python methods to find the sum of dictionary keys. Python provides several built-in functions that make this task efficient and straightforward. Methods Overview 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 Input and Expected Output Assume we have an input dictionary containing numeric keys. We will find the sum of all the keys using different methods ? Input inputDict = {4: 10, 1: 30, 10: ...

Read More

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

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 4K+ Views

In this article, we will learn a Python program to find the sum of characters' ASCII values in a list of strings. We'll explore two approaches: using loops and using list comprehension with built-in functions. Problem Overview Given a list of strings, we need to calculate the sum of ASCII values for each string's characters and return a list of these sums. Example For the input list ['hello', 'tutorialspoint', 'python', 'platform'], we calculate the ASCII sum for each word. For "hello", the ASCII values are h(104) + e(101) + l(108) + l(108) + o(111) = 532. ...

Read More

Python Program to Extract Strings with a digit

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 375 Views

When working with lists of strings, you often need to extract strings that contain at least one digit. Python provides several approaches to accomplish this task efficiently. Methods Overview 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 Problem Example Assume we have taken an input list containing strings. We will now extract strings containing a digit using the above methods ? Input string_list = ['hello562', 'tutorialspoint', ...

Read More

Python program to count the number of spaces in string

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 9K+ Views

In this article, we will learn how to count the number of spaces in a string using various Python methods. Counting spaces is useful for text analysis, validation, and formatting tasks. 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 from operator module Method 1: Using For Loop with Indexing This method iterates through each character using index positions and counts spaces manually ? def countSpaces(inputString): ...

Read More

Python Program to Count of Words with specific letter

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 2K+ Views

In this article, we will learn how to count words containing a specific letter in a string using Python. We'll explore four different approaches to solve this problem efficiently. Problem Statement Given an input string and a character, we need to count how many words contain that specific character. Example input_string = 'hello tutorialspoint python codes' input_char = "p" # Expected output: 2 (words: tutorialspoint, python) Method 1: Using List Comprehension with split() List comprehension provides a concise way to filter words containing the target character − # Input string ...

Read More

Python Program to Alternate list elements as key-value pairs

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 775 Views

In this article, we will learn how to get alternate list elements as key-value pairs in Python. This technique is useful when you need to transform a list into a dictionary by pairing elements at alternate positions. Assume we have an input list containing integers. We need to create key-value pairs where each element is paired with the element that appears two positions ahead ? Methods Used The following are the various methods used to accomplish this task ? Using for loop Using dictionary comprehension and list slicing ...

Read More

How to Common keys in list and dictionary using Python

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 982 Views

In this article, we will learn how to find common keys between a list and dictionary in Python. This is useful when you need to filter dictionary keys based on a list of allowed values. Methods Used The following are the various methods to accomplish this task − Using the 'in' operator and List Comprehension Using set() and intersection() functions Using keys() function & in operator Using the Counter() function Example Setup Assume we have taken an input dictionary and list. We will find the common elements between the input list and keys ...

Read More

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

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 289 Views

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. This problem involves comparing elements between a 2D matrix and a 1D list to calculate the absolute difference of their unique elements' sums. Problem Overview Given a matrix and a list, we need to − Find elements in the list that are not in the matrix Find elements in the matrix that are not in the list Calculate the absolute difference between their sums Example Let's understand with ...

Read More
Showing 1501–1510 of 21,090 articles
« Prev 1 149 150 151 152 153 2109 Next »
Advertisements