title: Dictionaries and for loops in functions
body: <p>I am currently working on my first website, which is a dna translator that you can translate your dna into a certain protein. To do that, I've created a class in views that goes like this:</p>
  <pre><code>class TranslatorView(View):
      template_name = 'main/translated.html'
  
      mapper_1={                           #Here's the protein dictionary
          &quot;aat&quot;: &quot;Asparagine&quot;,
          &quot;aac&quot;: &quot;Asparagine&quot;,
          &quot;aaa&quot;: &quot;Lysine&quot;,
          &quot;aag&quot;: &quot;Lysine&quot;,
          &quot;act&quot;: &quot;Threonine&quot;,
          &quot;acc&quot;: &quot;Threonine&quot;,
          &quot;aca&quot;: &quot;Threonine&quot;,
          &quot;acg&quot;: &quot;Threonine&quot;,
          &quot;agt&quot;: &quot;Serine&quot;,
          &quot;agc&quot;: &quot;Serine&quot;,
          &quot;aga&quot;: &quot;Arginine&quot;,
          &quot;agg&quot;: &quot;Arginine&quot;,
          &quot;att&quot;: &quot;Isoleucine&quot;,
          &quot;atc&quot;: &quot;Isoleucine&quot;,
          &quot;ata&quot;: &quot;Isoleucine&quot;,
          &quot;atg&quot;: &quot;Methionine&quot;,
          &quot;cat&quot;: &quot;Histidine&quot;,
          &quot;cac&quot;: &quot;Histidine&quot;,
          &quot;caa&quot;: &quot;Glutamine&quot;,
          &quot;cag&quot;: &quot;Glutamine&quot;,
          &quot;cct&quot;: &quot;Proline&quot;,
          &quot;ccc&quot;: &quot;Proline&quot;,
          &quot;cca&quot;: &quot;Proline&quot;,
          &quot;ccg&quot;: &quot;Proline&quot;,
          &quot;cgt&quot;: &quot;Arginine&quot;,
          &quot;cgc&quot;: &quot;Arginine&quot;,
          &quot;cga&quot;: &quot;Arginine&quot;,
          &quot;cgg&quot;: &quot;Arginine&quot;,
          &quot;ctt&quot;: &quot;Leucine&quot;,
          &quot;ctc&quot;: &quot;Leucine&quot;,
          &quot;cta&quot;: &quot;Leucine&quot;,
          &quot;ctg&quot;: &quot;Leucine&quot;,
          &quot;gat&quot;: &quot;Aspartic&quot;,
          &quot;gac&quot;: &quot;Aspartic&quot;,
          &quot;gaa&quot;: &quot;Glutamic&quot;,
          &quot;gag&quot;: &quot;Glutamic&quot;,
          &quot;gct&quot;: &quot;Alanine&quot;,
          &quot;gcc&quot;: &quot;Alanine&quot;,
          &quot;gca&quot;: &quot;Alanine&quot;,
          &quot;gcg&quot;: &quot;Alanine&quot;,
          &quot;ggt&quot;: &quot;Glycine&quot;,
          &quot;ggc&quot;: &quot;Glycine&quot;, 
          &quot;gga&quot;: &quot;Glycine&quot;,
          &quot;ggg&quot;: &quot;Glycine&quot;,
          &quot;gtt&quot;: &quot;Valine&quot;,
          &quot;gtc&quot;: &quot;Valine&quot;,
          &quot;gta&quot;: &quot;Valine&quot;,
          &quot;gtg&quot;: &quot;Valine&quot;,
          &quot;tat&quot;: &quot;Tyrosine&quot;,
          &quot;tac&quot;: &quot;Tyrosine&quot;,
          &quot;taa&quot;: &quot;Stop&quot;,
          &quot;tag&quot;: &quot;Stop&quot;,
          &quot;tct&quot;: &quot;Serine&quot;,
          &quot;tcc&quot;: &quot;Serine&quot;,
          &quot;tca&quot;: &quot;Serine&quot;,
          &quot;tcg&quot;: &quot;Serine&quot;,
          &quot;tgt&quot;: &quot;Cysteine&quot;,
          &quot;tgc&quot;: &quot;Cysteine&quot;,
          &quot;tga&quot;: &quot;Stop&quot;,
          &quot;tgg&quot;: &quot;Tryptophan&quot;,
          &quot;ttt&quot;: &quot;Phenylalanine&quot;,
          &quot;ttc&quot;: &quot;Phenylalanine&quot;,
          &quot;tta&quot;: &quot;Leucine&quot;,
          &quot;ttg&quot;: &quot;Leucine&quot;,
  
      }
  
  
  
      def translate_protein(self,phrase):     
          protein = &quot;&quot;
          for letter in phrase:
              if letter.lower() in self.mapper_1:
                  protein += self.mapper_1[letter.lower()].upper() if letter.isupper() else self.mapper_1[letter]
          return protein
  
      def get(self, request, *args, **kwargs):
          return render(request, 'main/translator.html')
  
      def post(self, request, *args, **kwargs):
          protein = request.POST.get('text','protein')
          return render(request, self.template_name, {'protein': self.translate_protein(protein)})
  </code></pre>
  <p>I probably have the problem in the dictionary and for loop, because to translate the protein, the forloop needs to get three letters because a codom (rna string) is grouped in three letters.</p>
  <p>Example:</p>
  <p>AAT should be translated into Asparagine. So the forloop shoul've got the three letters in the rna chain and translated it into Asparagine.</p>
  <p>Needless to say, Idk how to do that. So It'd be necessary some help.</p>
  <p>By the way, I hope I made myself clear with the explanation.</p>