title: reverse method mutating input
body: <p>For an assignment we were asked to create a function that would reverse all the elements in an arbitrarily nested list. So inputs to the function should return something like this:</p>
  
  <pre><code>&gt;&gt;&gt; seq = [1,[2,[3]]]
  &gt;&gt;&gt; print arb_reverse(seq)
  [[[3],2],1]
  &gt;&gt;&gt; seq = [9,[[],[0,1,[[],[2,[[],3]]]],[],[[[4],5]]]]
  &gt;&gt;&gt; print arb_reverse(seq)
  [[[[5,[4]]],[],[[[[3,[]],2],[]],1,0],[]],9]
  </code></pre>
  
  <p>I came up with a recursive solution which works well:</p>
  
  <pre><code>def arb_reverse(seq):
      result = []
      for element in reversed(seq):
          if not is_list(element):
              result.append(element)
          else:
              result.append(arb_reverse(element))
      return result
  </code></pre>
  
  <p>But for a bit of a personal challenge I wanted to create a solution without the use of recursion. One version of this attempt resulted in some curious behavior which I am not understanding. For clarification, I was NOT expecting this version to work properly but the resulting input mutation does not make sense. Here is the iterative version in question:</p>
  
  <pre><code>def arb_reverse(seq):
      elements = list(seq)   #so input is not mutated, also tried seq[:] just to be thorough
      result = []
      while elements:
          item = elements.pop()
          if isinstance(item, list):
              item.reverse() #this operation seems to be the culprit
              elements += item 
          else:
              result.append(item)
      return result
  </code></pre>
  
  <p>This returns a flattened semi-reversed list (somewhat expected), but the interesting part is what it does to the input (not expected)... </p>
  
  <pre><code>&gt;&gt;&gt; a = [1, [2, [3]]]
  &gt;&gt;&gt; arb_reverse(a)
  [2, 3, 1]
  &gt;&gt;&gt; a
  [1, [[3], 2]]
  &gt;&gt;&gt; p = [1, [2, 3, [4, [5, 6]]]]
  &gt;&gt;&gt; print arb_reverse(p)
  [2, 3, 4, 5, 6, 1]
  &gt;&gt;&gt; print p
  [1, [[[6, 5], 4], 3, 2]]
  </code></pre>
  
  <p>I was under the impression that by passing the values contained in the input to a variable using <code>list()</code> or <code>input[:]</code> as i did with <code>elements</code>, that I would avoid mutating the input. However, a few print statements later revealed that the reverse method had a hand in mutating the original list. Why is that?</p>