title: Assign values to array during loop - Python
body: <p>I am currently learning Python (I have a strong background in Matlab). I would like to write a loop in Python, where the size of the array increases with every iteration (i.e., I can assign a newly calculated value to a different index of a variable). For the sake of this question, I am using a very simple loop to generate the vector <code>t = [1 2 3 4 5]</code>. In Matlab, programming my desired loop would look something like this:</p>
  
  <pre><code>t = [];
  for i = 1:5
      t(i,1) = i;
  end
  </code></pre>
  
  <p>I have managed to achieve the same thing in Python with the following code:</p>
  
  <pre><code>result_t = []
  for i in range(1,5):
      t = i
      result_t.append(t)
  </code></pre>
  
  <p>Is there a more efficient way to assign values to an array as we iterate in Python? Why is it not possible to do <code>t[i,1] = i</code> (error: list indices must be integers or slices, not tuple) or <code>t.append(t) = t</code> (error: '<code>int</code>' object has no attribute 'append')?</p>
  
  <p>Finally, I have used the example above for simplicity. I am aware that if I wanted to generate the <code>vector [1 2 3 4 5]</code> in Python, that I could use the function "<code>np.arange(1,5,1)</code>"</p>
  
  <p>Thanks in advance for your assistance!</p>
  
  <p>-> My real intention isn't to produce the vector [1 2 3 4 5], but rather to assign calculated values to the index of the vector variable. For example:</p>
  
  <pre><code>result_b = []
  b = 2
  for i in range(1,5):
      t = i + b*t
      result_b.append(t) 
  </code></pre>
  
  <p>Why can I not directly write <code>t.append(t)</code> or use indexing (i.e., <code>t[i] =  i + b*t</code>)?</p>