title: How to avoid duplication when replacing by using two lists
body: <p>I'm working on replacing words using two lists</p>
  <pre><code>a = [&quot;Strawberry Cookie&quot;, &quot;Banana Cookie&quot;, &quot;Tomato Cookies&quot;, &quot;Pineapple Cookie&quot;, &quot;Apple Cookie&quot;]
  
  b = [&quot;Pineapple Cookie&quot;, &quot;Cookie Banana&quot;, &quot;Cookie Tomato&quot;, &quot;Strawberry Cookie&quot;, &quot;Cookie Apple&quot;]
  </code></pre>
  <p>Retrieves the string in variable text1 into a list (a) and replaces it with a list (b). The sequence of tasks is in the same order as the list.</p>
  <pre><code>text1 = &quot;&quot;&quot;
  
  Meaningless texts are listed aaaa
  
  aaaaaaaaa Strawberry Cookie aaaaaaa
  
  ccccc Meaningless texts are listed aaaaa
  
  aaaaaaaaa Banana Cookie aaaaaa
  bbbb Meaningless texts are listed aaaa
  
  aaaaaaaa Tomato Cookies aaaaaaaa
  
  aaaa Meaningless texts are listed aaaa
  aaaaaaaa Pineapple Cookie aaaaaaa
  
  aaaaaa Apple Cookie aaaaaaa
  gggsdgg Meaningless texts are listed affff
  
  dsddsssf
  
  &quot;&quot;&quot;
  </code></pre>
  <p>I tried the code below.</p>
  <pre><code>for x, y in zip(a, b):
      text1 = re.sub(x, y, text1, re.IGNORECASE)
  print text1
  
  &gt;&gt;&gt;Meaningless texts are listed aaaa
  
  aaaaaaaaa Strawberry Cookie aaaaaaa
  
  ccccc Meaningless texts are listed aaaaa
  
  aaaaaaaaa Cookie Banana aaaaaa
  bbbb Meaningless texts are listed aaaa
  
  aaaaaaaa Cookie Tomato aaaaaaaa
  
  aaaa Meaningless texts are listed aaaa
  aaaaaaaa Strawberry Cookie aaaaaaa
  
  aaaaaa Cookie Apple aaaaaaa
  gggsdgg Meaningless texts are listed affff
  
  dsddsssf
  </code></pre>
  <p>Due to the duplicate values of Strawberry Cookie and Pineapple Cookie in the list (a) and (b), the replacement operation is made twice and it returns to the original value.</p>
  <p>What I want is to set the value to not change once it is substituted.</p>
  <pre><code>new_text = []
  check_list = []
  num = 0
  division = text.split('\n')
  
  for line in division:
      for i in range(len(b)):
          if a[i] in line:
              if a[i] not in check_list:
                  check_list.append(b[i])
                  rrr = re.sub(a[i], b[i], line, re.IGNORECASE)
                  new_text.append(rrr)
                  break
              else:
                  check_list.append(b[i])
                  new_text.append(line)
  
          else:
              check_list.append(b[i])
              new_text.append(line)
              break
  </code></pre>
  <p>I've tried several times, but failed. Help</p>