title: Python | returning a variable
body: <p>I read and understand the whole article described in <a href="https://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference">other question</a>.</p>
  
  <p>My problem is regarding this <a href="http://norvig.com/sudoku.html" rel="nofollow noreferrer">source code</a>.</p>
  
  <p>the author returns values in function assign:</p>
  
  <pre><code>def assign(values, s, d):
      """Eliminate all the other values (except d) from values[s] and propagate.
      Return values, except return False if a contradiction is detected."""
      other_values = values[s].replace(d, '')
      if all(eliminate(values, s, d2) for d2 in other_values):
          return values
      else:
          return False
  </code></pre>
  
  <p>But assign is never used to set existing variable values in calling function parse_grid(grid): </p>
  
  <pre><code>def parse_grid(grid):
      values = dict((s, digits) for s in squares)
      for s,d in grid_values(grid).items():
          if d in digits and not assign(values, s, d):
              return False ## (Fail if we can't assign d to square s.)
      return values
  </code></pre>
  
  <p>So returning values seems rather unnecessary to me. Since he only uses assign() as a boolean, can't he just return true instead? </p>
  
  <p>I understood that returning a value doesn't change anything about the original variable. Only if the variable is passed as parameter and changed there without getting rebound to another variable, only then does the 'original' variable change because it holds the same reference.</p>
  
  <p>However the <code>return values</code> in <code>def parse_grid(grid</code>) should be a totally changed values then the one at the start of the function. When does this get assigned?</p>
  
  <p><strong>Question:</strong> </p>
  
  <p>Where does <code>values</code> in <code>def parse_grid(grid</code>) get changed? Because this function returns values and this returned values should not be the same as the one set at start of this function. So where did it get changed and how?</p>
  
  <p>It is called for example like this: <code>display(parse_grid(grid2))</code> </p>