title: Python append value to a list returned from a function via for loop
body: <p>I have a function:</p>
  
  <pre><code>def function(x,y):
      do something
      print a,b
      return a,b
  </code></pre>
  
  <p>Now I use a for loop like:</p>
  
  <pre><code>for i in range(10,100,10):
      function(i,30)
  </code></pre>
  
  <p>which prints the values <code>a,b</code> for the given input values via the for loop. 
  It also returns <code>a,b</code> if I say for example <code>function(10,30)</code> like:</p>
  
  <pre><code>Out[50]: (0.25725063633960099, 0.0039189363571677958)
  </code></pre>
  
  <p><strong>I would like to append the values of <code>a,b</code> obtained for my different input parameters <code>(x,y)</code> via the for loop to two empty lists.</strong> </p>
  
  <p>I tried</p>
  
  <pre><code>for i in range(10,100,10):
      list_a,list_b = function(i,30)
  </code></pre>
  
  <p>but <code>list_a</code> and <code>list_b</code> are still empty. </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>I have also tried:</strong></p>
  
  <pre><code>list_a = []
  list_b = []
  for i in range(10,100,10):
      list_a.append(function(i,30)[0])
      list_b.append(function(i,30)[1])
  </code></pre>
  
  <p>But <code>list_a</code> and <code>list_b</code> are empty! </p>
  
  <p><strong>What I don't understand is that</strong>, when I call </p>
  
  <p><code>function(10,30)[0]</code> </p>
  
  <p>for instance, <strong>it outputs a value! But why am I not able to append it to a list?</strong></p>
  
  <p><strong><em>Here is the entire function as asked by a few.</em></strong> </p>
  
  <pre><code>def function(N,bins):
      sample = np.log10(m200_1[n200_1&gt;N]) # can be any 1D array
      mean,scatter = stats.norm.fit(sample) #Gives the paramters of the fit to the histogram
      err_std = scatter/np.sqrt(len(sample))
  
      if N&lt;30:
          x_fit = np.linspace(sample.min(),sample.max(),100)
          pdf_fitted = stats.norm.pdf(x_fit,loc=mean,scale=scatter) #Gives the PDF, given the parameters from norm.fit
          print "scatter for N&gt;%s is %s" %(N,scatter)
          print "error on scatter for N&gt;%s is %s" %(N,err_std)
          print "mean for N&gt;%s is %s" %(N,mean)  
  
      else:
          x_fit = np.linspace(sample.min(),sample.max(),100)
          pdf_fitted = stats.norm.pdf(x_fit,loc=mean,scale=scatter) #Gives the PDF, given the parameters from norm.fit
          print "scatter for N&gt;%s is %s" %(N,scatter) 
          print "error on scatter for N&gt;%s is %s" %(N,err_std)
          print "mean for N&gt;%s is %s" %(N,mean)
  
      return scatter,err_std 
  </code></pre>