Articles on Trending Technologies

Technical articles with clear explanations and examples

Python Program to replace a word with asterisks in a sentence

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 4K+ 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 829 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 1K+ 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 942 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 1K+ 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 366 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

How can I remove the same element in the list by Python

Sumana Challa
Sumana Challa
Updated on 24-Mar-2026 3K+ Views

A list is a built-in Python data structure that stores an ordered collection of items. Lists often contain duplicate elements, which can cause data inaccuracies. In this article, we will explore several approaches to remove duplicate elements from a list while preserving the original order. Using set() Function The set() function accepts an iterable (like a list, tuple, or string) as a parameter and creates a set object. Since a set object does not accept duplicate values, converting a list to a set automatically removes duplicates. Example The following example removes duplicate elements using the set() ...

Read More

Can someone help me fix this Python Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 24-Mar-2026 230 Views

This Python program demonstrates fixing common syntax and logical errors in a conversational script. The original code had indentation problems and undefined variable issues that prevented it from running correctly. Common Issues in the Original Code The main problems were: Indentation errors − Missing indentation inside if blocks Undefined variables − Variable 'name' used before assignment Python 2 print syntax − Using print statements instead of print() function Logic flow − Variable defined in one branch but used in another Corrected Version Here's the fixed code with proper indentation, variable handling, and Python ...

Read More

Reply to user text using Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 24-Mar-2026 2K+ Views

You can create an interactive text-based response system using Python's if-elif-else statements and while loops. This approach ensures the program continues asking for input until the user provides a valid option. The key is to use int() to convert user input to an integer and validate it against the available options. Example Here's a complete interactive response system − print("Come-on in. Need help with any bags?") while True: # Loop continues until valid option is selected try: bag ...

Read More
Showing 7311–7320 of 61,299 articles
« Prev 1 730 731 732 733 734 6130 Next »
Advertisements