title: Why is that the two codes below produce same output whereas the logic is same? This is a problem on leetcode
body: <p>The question is : <a href="https://leetcode.com/problems/subsets/" rel="nofollow noreferrer">https://leetcode.com/problems/subsets/</a></p>
  <p><strong>First code</strong></p>
  <pre><code>class Solution:
      def subsets(self, nums: List[int]) -&gt; List[List[int]]:
          
          ans=[]
          
          def recursion(nums,tempAns):
              if(len(nums)==0):
                  ans.append(tempAns)
                  return
              
              temp1=tempAns[:]
              temp2=temp1
              temp2.append(nums[0])
              recursion(nums[1:],temp1)
              recursion(nums[1:],temp2)
          
          recursion(nums,[])
          return ans
  </code></pre>
  <p><strong>Second Code</strong></p>
  <pre><code>class Solution:
      def subsets(self, nums: List[int]) -&gt; List[List[int]]:
          
          ans=[]
          def recursion(nums,tempAns):
              if(len(nums)==0):
                  ans.append(tempAns)
                  return
              
              ch=nums[0]
              restofarray=nums[1:]
              temp=tempAns[:]
              temp.append(ch)
              recursion(restofarray,tempAns)
              recursion(restofarray,temp)
          
          recursion(nums,[])
          return ans
  </code></pre>
  <p>While the second one works, first one shows wrong output. Can I know the reason please?</p>