title: I am having trouble saving in a list integers taken from a file
body: <p>the exercise ask us to check whether the numbers contained in a file are a magic square or not. </p>
  
  <p>first of all I am triyng to create a list with all the values that I will then transform into a matrix and then check <code>if sum of first row == sum first column == sum of diagonal</code>.</p>
  
  <p>My problem is way more easy than the exercise:</p>
  
  <p>List L is the one I will modify into a matrix but I'd like to have it clean, I succeeded in having it as <code>L=[7,1,2,1,1,4,"\n" and so on]</code> but I am trying to save <strong>1,2 as 12 and 1,4 as 14.</strong> </p>
  
  <p>I tried to do it as the following but I get a str index out of range, that seems weird as I tried in every way to keep the <code>indexes &lt; than len-1</code>. could you kindly have a look?</p>
  
  <p>I know there may be other ways to implement the exercise, but in this moment I am interested in how edit list L into LI=[7, 12, 1, 14, "\n", 2, 13, 8, 11, "\n", 16, 3, 10, 5, "\n", 9, 6, 15, 4]</p>
  
  <pre><code>L=['7', ' ', ' ', ' ', ' ', '1', '2', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '1', '4', '\n', '2', ' ', ' ', ' ', ' ', '1', '3', ' ', ' ', ' ', ' ', '8', ' ', ' ', ' ', ' ', '1', '1', '\n', '1', '6', ' ', ' ', ' ', ' ', '3', ' ', ' ', ' ', ' ', '1', '0', ' ', ' ', ' ', ' ', '5', '\n', '9', ' ', ' ', ' ', ' ', '6', ' ', ' ', ' ', ' ', '1', '5', ' ', ' ', ' ', ' ', '4']
      LI=[ ]
      j=len(L)-1
      for i in range(0,j):
          for el in L:
              if el[i]!=" " and el[i+1]!=" ":
                  LI.append(el[i]*10+el[i+1])
              elif el!=" ":
                  LI.append(el)
      print(LI)
  </code></pre>
  
  <p><strong>Error -:</strong></p>
  
  <pre><code>---------------------------------------------------------------------------
      IndexError                                Traceback (most recent call last)
      &lt;ipython-input-164-73294659fea7&gt; in &lt;module&gt;
            4 for i in range(0,j):
            5     for el in L:
      ----&gt; 6         if el[i]!=" " and el[i+1]!=" ":
            7                 L.append(el[i]*10+el[i+1])
            8         elif el!=" ":
            IndexError: string index out of range
  ***
  </code></pre>