Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created December 27, 2022 09:19
Show Gist options
  • Save kshirsagarsiddharth/2aa76cb61e4912a7ecec5b5d86322176 to your computer and use it in GitHub Desktop.
Save kshirsagarsiddharth/2aa76cb61e4912a7ecec5b5d86322176 to your computer and use it in GitHub Desktop.
def remove_stop_words(text):
# Split the text into words
words = text.split()
# Define the stop words
stop_words = ['a', 'an', 'and', 'the', 'in', 'of']
# Remove stop words
clean_words = [word for word in words if word not in stop_words]
# Join the clean words into a single string
clean_text = ' '.join(clean_words)
return clean_text
# Test the function
text = "There is an stop word in a word"
remove_stop_words(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment