title: Appending lists to a global list in python
body: <p>I'm trying to generate a list of permutations (also lists) by appending a global list as each permutation is generated.  I can tell the permutations are being generated properly by printing each after it is generated.  However, after the function is called my global list only contains the original list for each time a permutation was generated by the function.</p>
  
  <pre><code>    array = []
  
      def perms(a, k):
          if (k == len(a)):
              global array
              array.append(a)
              print(a) #perms function is working properly
          else:
               for i in range(k, len(a)):
                       a[k], a[i] = a[i], a[k]
                       perms(a, k+1)
                       a[k], a[i] = a[i], a[k]
  
  
      perms([1,2,3,4], 0)
  
      #only prints the original list for each time a perm was generated
      for i in array: print(i)
  </code></pre>
  
  <p>When I am printing at the bottom it is showing array = [[1,2,3,4], [1,2,3,4], ...]</p>
  
  <p>It seems like my global list array can only see the perms parameter a in the scope it was called in.  </p>
  
  <p>How would this be done properly? </p>