title: How to compare strings and make changes?
body: <p>I have the below code which takes the user input (myWordsCopy) converts any characters entered in place of letters IE: @ = a, then converts any &quot;badWords&quot; to '*'.</p>
  <p>The issue is that now the entire string is a new one with 'converted' words.</p>
  <p>For example:</p>
  <p>(for this example; badword == a bad word)</p>
  <p>input - &quot;I have an email address; @xyz but it includes a b@dWord&quot;</p>
  <p>currently prints - &quot;i have an email address; axyz but it includes a ******&quot;</p>
  <p>what i want to print ;</p>
  <p>&quot;i have an email address; @xyz but it includes a ******&quot;</p>
  <p>I ideally would like to avoid adding every variation of &quot;badWord&quot; to my dictionary and rather compare any charters that are commonly used in place ie; @ = a , $ = s etc that is why I have taken the approach to convert the entire string.</p>
  <p>I tried to compare a copy of the original string with the new string and replace every instance of **** in the new back to the original ,I tried with a nested for Loop but these were not 'synced' so it didn't work without changing the entire string again.</p>
  <pre><code>
  myWords = input(&quot;Enter words&quot;)
  myWordsCopy = myWords.lower()
  badWords = {&quot;badword&quot;}
  wordDiction = { &quot;@&quot; : &quot;a&quot; , &quot;$&quot; : &quot;s&quot; }
  
  for char in myWordsCopy:
  
      if wordDiction.get(char):
  
          myWordsCopy = myWordsCopy.replace(char, wordDiction.get(char))
        
  for words in myWordsCopy.split(&quot; &quot;):
  
      if words in badWords:
  
          myWordsCopy = myWordsCopy.replace(words, '*'*len(words))
              
  print(myWordsCopy)
  </code></pre>