title: Very weird Python variable scope behaviour
body: <p>I'm having a problem with Python 2.7 that is driving me insane.</p>
  
  <p>I'm passing an array to some functions and altough that variable is suposed to be local, in the end the value of the variable inside main is changed.</p>
  
  <p>I'm a bit new to Python, but this goes against any common sense I got.</p>
  
  <p>Any ideas of what I'm doing wrong?</p>
  
  <pre><code>def mutate(chromo):
      # chooses random genes and mutates them randomly to 0 or 1
      for gene in chromo:
          for codon in gene:
              for base in range(2):
                  codon[randint(0, len(codon)-1)] = randint(0, 1)
      return chromo
  
  def mate(chromo1, chromo2):
      return mutate([choice(pair) for pair in zip(chromo1, chromo2)])
  
  
  if __name__ == '__main__':
      # top 3 is a multidimensional array with 3 levels (in here I put just 2 for simplicity)
      top3 = [[1, 0], [0, 0], [1, 1]]
  
      offspring = []
      for item in top3:
          offspring.append(mate(top3[0], item))
  
      # after this, top3 is diferent from before the for cycle
  </code></pre>
  
  <p><strong>UPDATE</strong>
  Because Python passes by reference, I must make a real copy fo the arrays before using them, so the <strong>mate</strong> functions must be changed to:</p>
  
  <pre><code>import copy
  def mate(chromo1, chromo2):
      return mutate([choice(pair) for pair in zip(copy.deepcopy(chromo1), copy.deepcopy(chromo2))])
  </code></pre>