Take the tour ×  I need to censor all occurrences of a list of
words with *'s. I have about 400 words in the list and it's
going to get hit with a lot of traffic, so I want to make it
very efficient. What's an efficient algorithm/data structure to
do this in? Preferably something already in Python.     1. "piss
off" => "**** off"   2. "hello" => "hello"   3. "go to hell" =>
"go to ****" share|improve this question Have you considered
using a regex? –  phs Aug 28 '12 at 2:50 Your example #2 doesn't
change –  nebffa Aug 28 '12 at 2:50 censoring: not that old
chestnut –  Mitch Wheat Aug 28 '12 at 2:51 Censor the words on
input and not when you want to show them. So you won't need to
worry about traffic –  JBernardo Aug 28 '12 at 2:52 @phs Regular
expressions won't be efficient enough. nebffa That's on purpose
to show that I specifically want to match whole words. –  marcog
Aug 28 '12 at 2:53 show 4 more comments  5 Answers  A case-
insensitive trie-backed set implementation might fit the bill.
For each word, you'