title: python compare two lists and replace original list if there is a match
body: <p>I have two lists containing strings. I want to take each item in the <code>base_list</code> and search to see if there is a match for the first 3 characters in any values from the <code>custom list</code>. If there is a match, replace the original value in <code>base_list</code> with the one from <code>custom_list</code>. If there is no match, keep the original value.</p>
  
  <pre><code>base_list = ["abc123", "cde123", "efg456", "ghi123"]
  
  custom_list = ["abc321", "efg654"]
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>modified_base_list = ["abc321", "cde123", "efg654", "ghi123"]
  </code></pre>
  
  <p>Eventually I also want to write this new <code>modified_base_list</code> as a file containing the items, one per line.</p>
  
  <p>I've tried:</p>
  
  <pre><code>modified_base_list = []
  
  for custom in custom_list:
      for base in base_list:
          if custom[:3] == base[:3]:
              modified_base_list.append(custom)
          else:
              modified_base_list.append(base)
  
  
  print(modified_base_list)
  
  with open('newfile.txt', 'w') as f:
      for s in modified_base_list:
          f.write(s)
  </code></pre>
  
  <p>***EDITING QUESTION to account for lists that have 15k+ lines to find a faster way to do this.</p>