title: Store swapped new array inside nested for
body: <p>How can I store this swapped new array inside nested for? After ending the loop this NEWstate becomes exactly like the given state a[2,1,5,0]. I was generating different states by swapping next elements. Need to store those swapped states.</p>
  <pre><code>def genrState(alist):
      
        NEW=[]
        print(&quot;Current state &quot;, alist)
        i=0
        for x in alist:
          print(&quot;for&quot;, x, &quot;index is  &quot;, i)
          j=i
          for y in alist[i+1:]:
            if i &lt; 10:
              alist[i] , alist[j+1] = alist[j+1], alist[i]
              print(&quot;generated&quot;, alist)
              NEWstate = alist
              print(&quot;NEW INSIDE&quot;, NEWstate ) 
            alist[i] , alist[j+1] = alist[j+1], alist[i]
            j=j+1`enter code here`
          i=i+1
          print(&quot;NEW&quot;, NEWstate )  
          print(alist)
      
      a=[2,1,5,0]
      genrState(a)
  </code></pre>