Programming Articles

Page 624 of 2547

Python program to split and join a string?

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 10K+ Views

We'll learn how to split and join a string in Python in this article. Python defines strings as a collection of characters enclosed in one, two, or three quotations. When a string is split, it is divided into smaller strings using a specific delimiter. A set of one or more characters used to define a boundary is known as a delimiter. The comma (, ), semicolon (;), tab (\t), space ( ), and pipe (|) are the most widely used delimiters. Input-Output Scenario Following is an input and its output scenario to demonstrate the split and join ...

Read More

Python program to multiply all numbers in the list?

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 27K+ Views

In this article, we will explore various methods to multiply all numbers in a list in Python. A list is an ordered collection of values enclosed in square brackets, and we'll create functions that multiply each value and return the product as a single result. For example, multiplying all numbers in the list [3, 2, 6] gives us 36. Let's examine different approaches to calculate the product of all numbers in a list. Using math.prod() Function The math.prod() function, introduced in Python 3.8, provides the most straightforward way to calculate the product of all numbers in a ...

Read More

Python program to Remove and print every third from list until it becomes empty?

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 2K+ Views

In this article, we will learn how to remove and print every third element from a list until it becomes empty using Python. This classic problem demonstrates circular traversal and dynamic list manipulation. Problem Understanding We need to repeatedly find and remove every third element from a list, starting from index 2 (third position). After removing an element, we continue counting from the next position in the modified list until all elements are removed. Input-Output Scenario Following is the input and its output scenario for removing and printing every third element from the list until it ...

Read More

Python Program to replace a word with asterisks in a sentence

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 3K+ Views

Asterisks (*) are commonly used in text processing to censor or hide sensitive words by replacing them with symbols. In Python, we can replace specific words with asterisks using several approaches. In this article, we will explore different methods to replace a word with asterisks in a sentence. Input-Output Example Here's what word replacement with asterisks looks like − Input: Welcome to the TutorialsPoint family Output: Welcome to the TutorialsPoint ****** The word "family" is replaced with six asterisks (matching its length). Using replace() Method The replace() method searches for a ...

Read More

Map function and Lambda expression in Python to replace characters

Samual Sam
Samual Sam
Updated on 24-Mar-2026 750 Views

Sometimes we need to swap specific characters in a string. Python's map() function combined with lambda expressions provides an elegant solution for character replacement operations. Problem Statement We want to replace character a1 with character a2 and a2 with a1 simultaneously. For example ? Input string: "puporials toinp" Characters to swap: p and t Expected output: "tutorials point" Using map() and Lambda Expression The map() function applies a lambda expression to each character in the string. The lambda handles the character swapping logic ? def replaceUsingMapAndLambda(sent, a1, ...

Read More

Map function and Dictionary in Python to sum ASCII values

Yaswanth Varma
Yaswanth Varma
Updated on 24-Mar-2026 936 Views

In this article, we are going to learn how to use the map() function along with dictionaries to sum the ASCII values of characters in strings. The Python built-in ord() function returns the ASCII integer value of a character. Additionally, dictionaries (dict) in Python are used to store key-value pairs. We use them to associate strings with their total ASCII values, making it easy to store and retrieve results. Python map() Function The Python map() function applies a function to every item in an iterable and returns a map object. Here's the syntax ? map(function, ...

Read More

Remove all duplicates from a given string in Python

Samual Sam
Samual Sam
Updated on 24-Mar-2026 854 Views

To remove all duplicates from a string in Python, we need to first split the string by spaces so that we have each word in an array. Then there are multiple ways to remove duplicates from the resulting list. We can remove duplicates by first converting all words to lowercase, then sorting them and finally picking only the unique ones. Let's explore different approaches ? Using Manual Loop with Sorting This approach converts words to lowercase, sorts them, and uses a loop to extract unique words ? sent = "Hi my name is John Doe ...

Read More

Tokenize text using NLTK in python

karthikeya Boyini
karthikeya Boyini
Updated on 24-Mar-2026 929 Views

Tokenization is the process of breaking down text into individual pieces called tokens. In NLTK and Python, tokenization converts a string into a list of tokens, making it easier to process text word by word instead of character by character. For example, given the input string ? Hi man, how have you been? We should get the output ? ['Hi', 'man', ', ', 'how', 'have', 'you', 'been', '?'] Basic Word Tokenization NLTK provides the word_tokenize() function to split text into words and punctuation marks ? from nltk.tokenize import ...

Read More

Python program to sort out words of the sentence in ascending order

karthikeya Boyini
karthikeya Boyini
Updated on 24-Mar-2026 1K+ Views

In order to sort the words of a sentence in ascending order, we first need to split the sentence into words using space as the splitting point. For simplicity, we'll only be splitting on space and let the punctuation be there. We can use replace or regex to remove that as well. Once we split the sentence, we can sort the words lexicographically (like in a language dictionary) using either sort() or sorted() methods depending on whether we want to sort the array in place or create a new sorted array. Using sort() Method (In-Place Sorting) When ...

Read More

Find all the patterns of \"10+1\" in a given string using Python Regex

Sumana Challa
Sumana Challa
Updated on 24-Mar-2026 292 Views

The term "10+1" is a specific pattern in a binary string that starts with a digit '1' followed by at least one or more '0' and ending with a '1'. In regular expressions, this pattern is represented as 10+1. Understanding the Pattern The regex pattern 10+1 breaks down as follows ? 1 − matches the literal character '1' 0+ − matches one or more occurrences of '0' 1 − matches the literal character '1' Using re.findall() The re.findall() method accepts a pattern and a string as parameters, finds the given pattern in the ...

Read More
Showing 6231–6240 of 25,466 articles
« Prev 1 622 623 624 625 626 2547 Next »
Advertisements