title: Python: TypeError: 'int' object is not subscriptable
body: <p>I get a TypeError and I don't understand why. The error is at <code>c = t[i][0]</code> (according to the debugger). I have 3 char groups(lists): <code>g1</code>, <code>g2</code> and <code>g3</code> and I'm trying to change the char's index by substracting the key's <code>k1</code>, <code>k2</code> or <code>k3</code> from the index. What I'm using now for testing: </p>
  
  <pre><code>text = 'abcd'
  
  l_text = [('a', 0), ('b', 1), ('c', 2), ('d', 3)]
  
  k1, k2, k3 = 2, 3, 1
  </code></pre>
  
  <p>And this is the code:</p>
  
  <pre><code>def rotate_left(text, l_text, k1, k2, k3):
      i = 0
      newstr = [None]*len(text)
      for t in l_text: # t = tuple
          c = t[i][0] 
          if c in g1: # c = char
              l = int(l_text[i][1]) # l = index of the char in the list
              if l - k1 &lt; 0:
                  newstr[l%len(text)-k1] = l_text[i][0]
              else:
                  newstr[l-k1] = l_text[i][0]
          elif c in g2:
              l = l_text[i][1] # l = index of the char in the list
              if l - k1 &lt; 0:
                  newstr[l%len(text)-k2] = l_text[i][0]
              else:
                  newstr[l-k2] = l_text[i][0]
          else:
              l = l_text[i][1] # l = index of the char in the list
              if l - k1 &lt; 0:
                  newstr[l%len(text)-k3] = l_text[i][0]
              else:
                  newstr[l-k3] = l_text[i][0]
          i += 1
      return newstr
  </code></pre>
  
  <p>Can someone explain me why do I get this error and how do I fix it? It's not like I'm using an <code>int</code> type there. The debugger shows it's a str type and it breaks after the 2nd iteration.</p>
  
  <p>PS google didn't help
  PPS I know there is too much repetition in the code. I did it to see in the debugger what's happening.</p>
  
  <p>UPDATE:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/hometriplerotatie.py", line 56, in &lt;module&gt;
      print(codeer('abcd', 2, 3, 1))
    File "/home/triplerotatie.py", line 47, in codeer
      text = rotate_left(text, l_text, k1, k2, k3)
    File "/home/triplerotatie.py", line 9, in rotate_left
      c = t[i][0] 
  TypeError: 'int' object is not subscriptable
  </code></pre>