title: How to create codes for pig latin and izzle translation and a code to apply them both?
body: <p><strong>Goal:</strong>
  So, my goal is to write a code to translate a word to pig latin and izzle languages. And then write another code <strong>&quot;apply_language_game&quot;</strong> which takes input some data and another input which is the language they want to transfer in (either pig latin or izzle)</p>
  <p><strong>Pig Latin:</strong>
  Pig Latin is one of the most famous English language games. You can convert an English word into Pig
  Latin by moving all the consonants up to the first vowel to the end of the word and then appending &quot;ay&quot;.
  In ‘hello’, h is before first vowel so it will be pushed at the end of word ‘elloh’ and then appending ‘ay’
  gives: ‘Ellohay’
  In Chris: Chr are before first vowel so they will be pushed at the end of sentence.
  E.g. &quot;hello, Chris how are you?&quot; becomes &quot;Ellohay, ischray owhay areay ouyay?&quot;</p>
  <p><strong>Izzle:</strong>
  You can convert
  an English word into -izzle speak by replacing the last vowel and all its following consonants with &quot;-izzle.&quot;
  E.g. &quot;Merry Christmas&quot; becomes &quot;Mizzle Christmizzle.&quot; If a word only has one vowel like 'and' and 'a' or
  it doesn't contain a cardinal vowel, [a, e, i, o, u], like the word 'my' you can either replace the entire
  word with 'izzle' or append '-izzle' to the end of the word.</p>
  <p><strong>Codes:</strong>
  So, I have written codes to convert a word into pig latin and izzle.
  Here is pig_latin one:</p>
  <pre><code>def pig_latin(word):
      word = list(word)
      vowels = ['a', 'e', 'i', 'o', 'u']
      vowel = [x for x in word if x in vowels]
      vowel1 = vowel[0]
      for i in word:
          if word.index(i) &lt; word.index(vowel1):
              ind = word.index(i)
              word.pop(ind)
              word.append(i)
      word.append(&quot;ay&quot;)
      return &quot;&quot;.join(word)
  </code></pre>
  <p>Here is izzle one:</p>
  <pre><code>def izzle(word):
      word = list(word)
      vowels = ['a', 'e', 'i', 'o', 'u']
      vowel = [x for x in word if x in vowels]
      if vowel == [] or len(&quot;&quot;.join(vowel)) == 1:
          return &quot;&quot;.join(word) + &quot;izzle&quot;
      else:
          vowel1 = vowel[-1]
          for i in word:
              if word.index(i) &gt;= word.index(vowel1):
                  ind = word.index(i)
                  word.pop(ind)
      word.append(&quot;izzle&quot;)
      return &quot;&quot;.join(word)
  </code></pre>
  <p>And here is the code for apply_language_game:</p>
  <pre><code>def apply_language_game(text, language_game):
      text = text.split()
      if language_game == pig_latin:
          lst = [pig_latin(x) for x in text]
          return &quot; &quot;.join(lst)
      if language_game == izzle:
          lst = [izzle(x) for x in text]
          return &quot; &quot;.join(lst)
  </code></pre>
  <p>Now if I want to test my code by converting a file containing some data into pig latin and izzle.
  <strong>The file contains:</strong>
  &quot;Fruits and Vegetables and Vegetables on a Budget and Vegetables at a Store and Vegetables to Clean Fruit and Vegetables&quot;</p>
  <p>The code works fine for pig latin but it doesn't work for izzle.
  <strong>Following Error is shown:</strong></p>
  <pre><code>Traceback (most recent call last):
    File &quot;&lt;input&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;C:\Program Files\JetBrains\PyCharm Community Edition 2020.2.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py&quot;, line 197, in runfile
      pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    File &quot;C:\Program Files\JetBrains\PyCharm Community Edition 2020.2.4\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py&quot;, line 18, in execfile
      exec(compile(contents+&quot;\n&quot;, file, 'exec'), glob, loc)
    File &quot;C:/Users/Dell/PycharmProjects/pythonHW3/word_analyzer.py&quot;, line 84, in &lt;module&gt;
      print(apply_language_game(text, izzle))
    File &quot;C:/Users/Dell/PycharmProjects/pythonHW3/word_analyzer.py&quot;, line 67, in apply_language_game
      lst = [izzle(x) for x in text]
    File &quot;C:/Users/Dell/PycharmProjects/pythonHW3/word_analyzer.py&quot;, line 67, in &lt;listcomp&gt;
      lst = [izzle(x) for x in text]
    File &quot;C:/Users/Dell/PycharmProjects/pythonHW3/word_analyzer.py&quot;, line 40, in izzle
      if word.index(i) &gt;= word.index(vowel1):
  ValueError: 'i' is not in list
  </code></pre>
  <p>Please tell me How can I solve this? Or if something is wrong with any of my code or I can how improve my code?</p>
  <pre><code></code></pre>