title: Search methods and string matching in python
body: <p>I have a task to search for a group of specific terms(around 138000 terms) in a table made of 4 columns and 187000 rows. The column headers are <code>id</code>, <code>title</code>, <code>scientific_title</code> and <code>synonyms</code>, where each column might contain more than one term inside it. </p>
  
  <p>I should end up with a csv table with the id where a term has been found and the term itself. What could be the best and the fastest way to do so?</p>
  
  <p>In my script, I tried creating phrases by iterating over the different words in a term in order and comparing each word with each row of each column of the table. </p>
  
  <p>It looks something like this:</p>
  
  <pre><code>title_prepared = string_preparation(title)
  sentence_array = title_prepared.split(" ")
  length = len(sentence_array)
  
  for i in range(length):
  
      for place_length in range(len(sentence_array)):
  
          last_element = place_length + 1
          phrase = ' '.join(sentence_array[0:last_element])
  
          if phrase in literalhash:
              final_dict.setdefault(id,[])
              if not phrase in final_dict[id]:
                  final_dict[trial_id].append(phrase)
  </code></pre>
  
  <p>How should I be doing this?</p>