title: What exactly does this return statement instruct the program to do?
body: <p>Here is a recursive solution the 8 queens problem from <a href="https://wiki.python.org/moin/SimplePrograms" rel="nofollow">https://wiki.python.org/moin/SimplePrograms</a> . I am having difficulty in understanding how/why the return statement in the solve function works. At first glance, it looks like it breaks rules (like, solutions hasn't been declared or assigened value before the loop in the return statement, but it appears before the loop in the return statement) but I can run this successfully so I am curious to understand how it works and why someone may have chosen to write it this way (to be confusing? short? because of other restrictions I do not yet understand?)</p>
  
  <pre><code>BOARD_SIZE = 8
  
  def under_attack(col, queens):
      left = right = col
  
      for r, c in reversed(queens):
          left, right = left - 1, right + 1
  
          if c in (left, col, right):
              return True
      return False
  
  def solve(n):
      if n == 0:
          return [[]]
  
      smaller_solutions = solve(n - 1)
  
      return [solution+[(n,i+1)]
          for i in xrange(BOARD_SIZE)
              for solution in smaller_solutions
                  if not under_attack(i+1, solution)]
  for answer in solve(BOARD_SIZE):
      print answer
  </code></pre>
  
  <p>I am familiar with recursive solutions to problems from some experimentation and a course I've taken, but I am pretty new to python as a whole (I mostly have used java and C in classes and on my own). </p>
  
  <p>Does anyone have a good way to explain how this syntax works or maybe other examples I can study that might help me make sense of it? This has really itched my curiosity...</p>