Detecting the slang in the given line

Slang, the informal language used in everyday communication, adds flavor and color to conversations. However, when dealing with formal text or analyzing sentiment, detecting slang can be crucial. In this tutorial, we’ll explore how to detect slang in text.

Program of detecting Slang

Let us see it with examples,

To search for a specific slang word in a sentence, please enter the slang term that you would like to find. Here is an example of slang words

slang = ['bcz', 'gm', 'gn', 'btw', 'bff', 'omg', 'rn']

Great! Let’s move forward with implementing the function for finding slang. By doing so, we will be able to identify and distinguish slang words from standard vocabulary. This will be a valuable tool in improving language processing and understanding in various fields, such as linguistics, education, and even social media analysis.

def contains_slang(en):
    words = en.split()
    return any(word in slang for word in words)

Then create a variable and check whether a particular slang is present in a string or not, you can define the variable and assign it the value of the slang you want to search for.

en = "btw"

To make the output more informative using if-else statements, you can add conditions that check for specific criteria and print corresponding messages accordingly. This way, the output will provide more clarity to the user.

if contains_slang(en):
    print("The given string contains slang words.")
else:
    print("The given string does not contain the slang words.")

Output:

Here is the output for the above code.

The given string contains slang words.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top