- July 16, 2009
- tag profanity
- -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.
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
- Detect iPhone & Switch Template via render_to_response by bryanhelmig 5 years, 8 months ago
- Profanity Function (Disemvowel) by areich 6 years, 7 months ago
- CleanCharField by DvD 8 years, 4 months ago
- If in list template tag by udfalkso 8 years, 7 months ago
- custom template filter to check if list contains any non-empty element by doniyor 1 year, 5 months ago