title: How to get the second element of index in 2d list
body: <p>I am trying to get the second index of element in 2nd list in python. The problem is that I can't do that because I get a problem free variable x referenced before assignment in enclosing space. My idea is for example if I got A in plaintext x will be 0, if i got b in key y will be 1. So I want to get the first index for letter in key, the second for letter in plaintext. It is possible? My code:</p>
  <pre><code>def making_dimensional_list(grid):
      global grid2
      grid2 = [list(line) for line in grid.split(&quot;\n&quot;)]
      return grid2
  print(making_dimensional_list(&quot;&quot;&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ
  BCDEFGHIJKLMNOPQRSTUVWXYZA
  CDEFGHIJKLMNOPQRSTUVWXYZAB
  DEFGHIJKLMNOPQRSTUVWXYZABC
  EFGHIJKLMNOPQRSTUVWXYZABCD
  FGHIJKLMNOPQRSTUVWXYZABCDE
  GHIJKLMNOPQRSTUVWXYZABCDEF
  HIJKLMNOPQRSTUVWXYZABCDEFG
  IJKLMNOPQRSTUVWXYZABCDEFGH
  JKLMNOPQRSTUVWXYZABCDEFGHI
  KLMNOPQRSTUVWXYZABCDEFGHIJ
  LMNOPQRSTUVWXYZABCDEFGHIJK
  MNOPQRSTUVWXYZABCDEFGHIJKL
  NOPQRSTUVWXYZABCDEFGHIJKLM
  OPQRSTUVWXYZABCDEFGHIJKLMN
  PQRSTUVWXYZABCDEFGHIJKLMNO
  QRSTUVWXYZABCDEFGHIJKLMNOP
  RSTUVWXYZABCDEFGHIJKLMNOPQ
  STUVWXYZABCDEFGHIJKLMNOPQR
  TUVWXYZABCDEFGHIJKLMNOPQRS
  UVWXYZABCDEFGHIJKLMNOPQRST
  VWXYZABCDEFGHIJKLMNOPQRSTU
  WXYZABCDEFGHIJKLMNOPQRSTUV
  XYZABCDEFGHIJKLMNOPQRSTUVW
  YZABCDEFGHIJKLMNOPQRSTUVWX
  ZABCDEFGHIJKLMNOPQRSTUVWXY&quot;&quot;&quot;))
  
  
  
  def making_2_lists(keyword,text):
      global key,plaintext
      key= []
      # plaintext = &quot;to jest bardzo tajny tekst&quot;
      text = text.upper()
      text = text.replace(&quot; &quot;, &quot;&quot;)
      plaintext = list(text)
      # keyword = &quot;tajne&quot;
      keyword = keyword.upper()
      keyword = keyword.replace(&quot; &quot;, &quot;&quot;)
      keyword = list(keyword)
      for j in range(len(text)):
          key.append(keyword[j%len(keyword)])
      return plaintext,key
  print(making_2_lists(&quot;tajne&quot;,&quot;To jest bardzo tajny tekst&quot;))
  
  def encrypt_vigenere(plaintext,key,grid2):
      for symbol in plaintext:
          x = [x for symbol in grid2 if symbol in grid2[0][x]]
      for letter in key:
          y = [y for letter in grid2 if letter in grid2[y][0]]
  
  
      return x,y
  print(encrypt_vigenere(plaintext,grid2,key))
  </code></pre>