
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

3K+ Views
The use of the symbol * (asterisks) in writing or printing as a reference mark, a sign that some letters or words have been omitted, a way to indicate a possible but unproven linguistic form, or for other arbitrary purposes. In this article we will discuss different ways to replace a word with asterisks in a sentence in Python. Input-Output Scenarios Following is an input and its output scenario of replacing a word in a sentence with asterisks − Input: Welcome to the TutorialsPoint family. Output: Welcome to the TutorialsPoint ****** We can see in the above scenario that ... Read More

654 Views
We want to replace a character a1 with a character a2 and a2 with a1. For example, For the input string, "puporials toinp"and characters p and t, we want the end string to look like −"tutorials point"For this we can use map function and lambdas to make the replacement. The map(lambda, input) function iterates over each item passed to it(in form of iterable input) and apply the lambda expression to it. So we can use it as follows −Example Live Demodef replaceUsingMapAndLambda(sent, a1, a2): # We create a lambda that only works if we input a1 or a2 and swaps them. ... Read More

792 Views
In this article, we are going to learn how to use the map() function along with dictionaries to add the ASCII values of characters in the string. 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 the result. Before diving into the examples, let's have a quick look at the Python map() function and the Python ord() function. Python map() Function The Python map() function ... Read More

757 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.We can remove duplicates by first converting all words to lowercase, then sorting them and finally picking only the unique ones. For example, Examplesent = "Hi my name is John Doe John Doe is my name" # Seperate out each word words = sent.split(" ") # Convert all words to lowercase words = map(lambda x:x.lower(), words) # Sort the words in order words.sort() ... Read More

851 Views
Given a character sequence and a defined document unit, tokenization is the task of chopping it up into pieces, called tokens, perhaps at the same time throwing away certain characters, such as punctuation. In the context of nltk and python, it is simply the process of putting each token in a list so that instead of iterating over each letter at a time, we can iterate over a token.For example, given the input string −Hi man, how have you been?We should get the output −['Hi', 'man', ', ', 'how', 'have', 'you', 'been', '?']We can tokenize this text using the word_tokenize ... Read More

791 Views
In NLP(Natural Language Processing), stop words are the words that are filtered out before or after processing text data, such as "is", "and", "a" etc. These words do not add meaning to the text and can be removed to improve the efficiency. The Natural Language Toolkit (NLTK) is the python library that provides the easy to use interface and the tools for text processing such as tokenization and stop word removal. In this article, we will explore how to remove stop words using NLTK. NLTK Stop Words Before going to use the NLTK stop words, we have ... Read More

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 sort it, then return a new array.In place sorting: when we want to sort the array/list ... Read More

3K+ Views
Lexicographical order is similar way the words are arranged in a dictionary. In this article, we are going to learn how to sort the words in lexicographical order, which means arranging them in alphabetical order (A-Z). Python provides built-in methods like split() and sorted() to perform this operation. Using Python split() Method The Python split() method is used to split a string by using the specified separator. This separator is a delimiter string and can be a comma, a full stop, or any other character to split a string. Syntax Following is the syntax of Python str.split() method ... Read More

5K+ Views
Email addresses are pretty complex and do not have a standard being followed all over the world which makes it difficult to identify an email in a regex. The RFC 5322 specifies the format of an email address. We'll use this format to extract email addresses from the text.For example, for a given input string −Hi my name is John and email address is john.doe@somecompany.co.uk and my friend's email is jane_doe124@gmail.comWe should get the output −john.doe@somecompany.co.uk jane_doe124@gmail.comWe can use the following regex for exatraction −[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+We can extract the email addresses using the find all method from re module. For example, ... Read More

218 Views
The term "10plus1" 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 Using re.findall() The re.findall() method accepts a pattern and a string as parameters, finds the given pattern in the entire string, and returns all the matches in the form of a list.To find the patterns of "10+1" in a given string, we just need to pass the same as pattern to the findall() method along with the string.Example ... Read More