title: Python: How to store for loop result in a list?
body: <p>I have my output as below which is the result of iteration over looping. Basically the code below is to compare arrays of different sizes using intersection and union calculation.:<br><br></p>
  
  <pre><code>import numpy as py
  import itertools
  from itertools import izip
  def diffs(a,b):
  # collect sliding window differences
  # length of window determined by the shorter array
  # if a,b are not arrays, need to replace b[...]-a with
  # a list comprehension
      n,m=len(a),len(b)
      if n&gt;m:
      # ensure s is the shorter
          b,a=a,b # switch
          n,m=len(a),len(b)
      # may need to correct for sign switch
      result=[]
      for i in range(0,1+m-n):
          result.append(b[i:i+n]-a)
      return result
  
  ###################################################################
  
  def alldiffs(a,b):
  # collect all the differences for elements of a and b
  # a,b could be lists or arrays of arrays, or 2d arrays
      result=[]
      for aa in a:
          for bb in b:
              result.append(diffs(aa,bb))
      return result
  
  ###################################################################
  
  def count_total(a,b):
  #count the total number of element for two arrays in different list
  #return [sum(map(len, i)) for i in product(a, b)]
      y= lambda x:len(x)
      result=[]
      for a1 in a:
          for b1 in b:
              result.append(y(a1) + y(b1))
      return result
  
  ##################################################################
  
  def count_zero(obj):
  #count the total number of zero for two arrays in different list
      if isinstance(obj,list):
          return list(map(count_zero,obj))
      else:
          return Counter(obj)[0]
  
  a=[np.array([2,2,1,2]),np.array([1,3])]
  b=[np.array([4,2,1])]
  c=[np.array([1,2]),np.array([4,3])]
  
  for i,j in itertools.combinations([a,b,c],2):
      all_diffs=alldiffs(i,j)
      total=count_total(i,j)
      zero=count_zero(all_diffs)
      total=np.array(total)
      union=map(sub,total,zero)
      zero=np.array(zero).tolist()
      union=np.array(union).tolist()
      union=[list(x) for x in union]  
      sim=[[float(aaa) / bbb for (aaa, bbb) in itertools.izip(aa, bb)] \
          for (aa, bb) in itertools.izip(zero, union)]
      sim_comb=sum(sim,[])
      sum_of_sim=sum(sim_comb)
      number_sum=len(sim_comb)
      ave=sum_of_sim/number_sum
      one_ave=1-ave
      print one_ave
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>&gt;&gt;&gt; 
  0.9
  0.829166666667
  0.875
  </code></pre>
  
  <p>How can I save them into list so my output will be like:</p>
  
  <pre><code>&gt;&gt;&gt;
  [0.9,0.829166666667,0.875]
  </code></pre>
  
  <p>Can anyone help me?</p>