title: Python : find and replace patterns in the value of dictionary that is a list of strings
body: <p>I have a dictionary that contains pairs of key:value where the value is a list of strings :</p>
  
  <pre><code>dictionarylst = {0:["example inside some sentence", "something else", "some blah"], 1:["testing", "some other word"], 2:["a new expression", "my cat is cute"]}
  </code></pre>
  
  <p>I also have a list of words that can be tokens or bigrams :</p>
  
  <pre><code>wordslist = ["expression 1", "my expression", "other", "blah"]
  </code></pre>
  
  <p>I am trying to match every word in my wordslist to every text in every value in my dictionary. And when there is a match, I want to replace just that pattern with a white space (but keep the rest of the text) and store the output in a new dictionary with the same keys.</p>
  
  <p>This what I have tried so far :</p>
  
  <pre><code>dictionarycleaned = {}
  for key,value in dictionarylst.items():
      for text in value :
          for word in wordslist :
              if word in value :
                  pattern = re.compile(r'\b({})\b'.format(word))
                  matches = re.findall(pattern, text)
                  dictionarycleaned[key] = [re.sub(i,' ', text) for i in matches]
              else :
                  dictionarycleaned[key] = value
  </code></pre>
  
  <p>This is matching only a small portion of the patterns in my wordlist. I tried different variations : like matching the pattern to the whole list of strings in every value or iterating over wordlist before dictionarylst, but nothing seems to clean all my data (which is very large).</p>
  
  <p>Thank you for your suggestions.</p>