Python Articles

Page 171 of 855

Python Program to Replace all words except the given word

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

In this article, we will learn how to replace all words except the given word in a string in Python. This technique is useful for text processing where you want to mask certain words while preserving specific keywords. Methods Used The following are the various methods to accomplish this task: Using For Loop, split() & join() Functions Using List Comprehension Problem Statement Given an input string, we need to replace all words with a replacement character except for one specific word that should remain unchanged. Input ...

Read More

Python Program to Remove numbers with repeating digits

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

In this article, we will learn how to remove numbers with repeating digits from a list in Python. Numbers like 3352 (3 appears twice) or 661 (6 appears twice) will be filtered out, keeping only numbers with unique digits. Problem Example Given an input list of numbers, we need to remove all numbers containing repeating digits ? Input inputList = [3352, 8135, 661, 7893, 99] Expected Output [8135, 7893] In the above example, 3352 has digit 3 repeated twice, 661 has digit 6 repeated, and 99 has digit 9 ...

Read More

Python program to remove K length words in String

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

In this article, we will learn how to remove all words of a specific length (K) from a string using Python. This is useful for text processing tasks where you need to filter words based on their character count. Problem Statement Given an input string and a value K, we need to remove all words that have exactly K characters and return the modified string. Example inputString = "hello tutorialspoint python codes" k_length = 5 The output will be ? Resultant string after removing 5 length words: tutorialspoint python ...

Read More

Python Program to Remove all digits before given Number

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

In this article, we will learn how to remove all digits before a given number from a string in Python. This task is useful when processing text data where you need to clean up numeric content selectively. Problem Overview Given an input string containing words and numbers, we want to remove all standalone digits that appear before a specific target number, while keeping the target number and everything after it intact. Example Consider this input ? inputString = 'hello 6 8 10 tutorialspoint 15 python codes' inputNumber = 10 The expected output ...

Read More

Python Program to move numbers to the end of the string

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

In this article, we will learn different methods to move all numeric digits from their current positions to the end of a string while preserving the order of non-digit characters. Problem Overview Given a string containing letters, digits, and spaces, we need to extract all digits and append them to the end while keeping other characters in their original order. Input inputString = 'hello5691 tutorialspoint1342' Output Resultant string after adding digits at the end: hello tutorialspoint56911342 Here all the numbers 56911342 contained in the input string are moved to the end ...

Read More

Python Program to Join strings by multiple delimiters

Vikram Chiluka
Vikram Chiluka
Updated on 27-Mar-2026 573 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 865 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 373 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
Showing 1701–1710 of 8,549 articles
« Prev 1 169 170 171 172 173 855 Next »
Advertisements