Found 34488 Articles for Programming

Removing stop words with NLTK in Python

Samual Sam
Updated on 20-Jun-2020 08:26:09

522 Views

When computers process natural language, some extremely common words which would appear to be of little value in helping select documents matching a user need are excluded from the vocabulary entirely. These words are called stop words.For example, if you give the input sentence as −John is a person who takes care of the people around him.After stop word removal, you'll get the output −['John', 'person', 'takes', 'care', 'people', 'around', '.']NLTK has a collection of these stopwords which we can use to remove these from any given sentence. This is inside the NLTK.corpus module. We can use that to filter ... Read More

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

karthikeya Boyini
Updated on 20-Jun-2020 08:29:57

992 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

Sort the words in lexicographical order in Python

Samual Sam
Updated on 20-Jun-2020 08:30:41

3K+ Views

Sorting words in lexicographical order mean that we want to arrange them first by the first letter of the word. Then for the words whose first letter is the same, we arrange them within that group by the second letter and so on just like in a language's dictionary(not the data structure).Python has 2 functions, sort and sorted for this type of order, let us look at how and when to use each of these methods.In place sorting: when we want to sort the array/list in place, ie, changing the order in the current structure itself, we can use the ... Read More

Extracting email addresses using regular expressions in Python

karthikeya Boyini
Updated on 20-Jun-2020 08:41:36

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

Regex in Python to put spaces between words starting with capital letters

Samual Sam
Updated on 20-Jun-2020 08:43:36

655 Views

The problem we are trying to solve here is to convert CamelCase to separate out words. We can solve this directly using regexes by finding all occurrences of a capital letter in the given string and put a space before it. We can use the sub method from the re module.For example, for the input string −AReallyLongVariableNameInJavaWe should get the output −A Really Long Variable Name In JavaWe can use "[A-Z]" regex to find all uppercase letters, then replace them with space and that letter again. We can implement it using the re package as follows −Example Live Demoimport re ... Read More

Python Regex to extract maximum numeric value from a string

karthikeya Boyini
Updated on 20-Jun-2020 08:21:49

343 Views

The easiest way to extract the maximum numeric value from a string using regex is to −Use the regex module to extract all the numbers from a stringFind the max from these numbersFor example, for the input string −There are 121005 people in this city, 1587469 in the neighboring city and 18775994 in a far-off city.We should get the output −18775994We can use "\d+" regex to find all numbers in a string as \d signifies a digit and the plus sign finds the longest string of continuous digits. We can implement it using the re package as follows −import re ... Read More

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

Samual Sam
Updated on 20-Jun-2020 08:22:04

75 Views

We need to find the regex pattern 10+1 in a given string. For this, we can use the re module available in python. This package has a method called find all that accepts the regex and the string we want to search in. It gives us all the occurrences of the pattern in that string. For example,For the input string −10000001 hello world 10011 test100000001test.We should get the output −10000001 1001 100000001We can implement it using the re package as follows −import re occ = re.findall("10+1", "10000001 hello world 10011 test100000001test.") for i in occ: print(i)This will give the output −10000001 1001 100000001

CountDownLatch in Java

Janani Jaganathan
Updated on 13-Oct-2022 11:25:00

3K+ Views

For a concurrent execution, CountDownLatch in Java is an important class that ensures one or more threads are in the queue for other threads to complete their set of operations. To better understand CountDownLatch in Java, in this article, you will learn the working of CountDownLatch with an example and methods of CountDownLatch. CountDownLatch in Java and its Working Process Based on the count value, the CountDownLatch is used for several purposes, which are as follows − When we begin the CountDownlatch with count value 1, it will simply work as an on/off latch or gate. On the other ... Read More

Compare two strings lexicographically in C#

karthikeya Boyini
Updated on 19-Jun-2020 12:11:36

2K+ Views

To compare strings in C#, use the compare() method. It compares two strings and returns the following integer values −If str1 is less than str2, it returns -1. If str1 is equal to str2, it returns 0. If str1 is greater than str2, it returns 1.Set the two strings in the String.compare() method and compare them −string.Compare(string1, string2);ExampleYou can try to run the following code to compare two strings in C#.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {         ... Read More

Common Language Runtime (CLR) in C#.NET

Samual Sam
Updated on 19-Jun-2020 12:12:53

5K+ Views

Common Language Runtime (CLR) manages the execution of .NET programs. The just-in-time compiler converts the compiled code into machine instructions. This is what the computer executes.The services provided by CLR include memory management, exception handling, type safety, etc.Let us see the features of Common Language Runtime (CLR) in C#:ComponentsComponents in other languages can be easily worked upon with CLR.ThreadingThe CLR provides support for threads to create multithreaded applications.Class Library SupportIt has built-in types and libraries for assemblies, threading, memory management, etc.DebuggingCLR makes code debugging easier.Garbage CollectionIt provides automatic garbage collection in C#.

Advertisements