Login

Profanity Check

Author:
menendez
Posted:
July 16, 2009
Language:
Python
Version:
1.0
Tags:
tag profanity
Score:
-2 (after 2 ratings)

Simple Python snippet to detect if any word in a list of words is inside your string. Use for profanity checking (my use case), auto tag detection, scoring, etc.

This will return an empty list if the word is not in the list. Assumes everything in words_to_find is lower case. Can probably be done cleaner with regular expressions but this method is extremely readable for those that prefer none regex solutions.

1
2
def find_words(string, words_to_find):
    return [x for x in string.replace(',', '').lower().split() if x in words_to_find]

More like this

  1. Serialize a model instance by chriswedgwood 1 week, 1 day ago
  2. Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 9 months, 1 week ago
  3. Crispy Form by sourabhsinha396 10 months ago
  4. ReadOnlySelect by mkoistinen 10 months, 2 weeks ago
  5. Verify events sent to your webhook endpoints by santos22 11 months, 2 weeks ago

Comments

Please login first before commenting.