title: python closure with assigning outer variable inside inner function
body: <p>I've got this piece of code:</p>
  
  <pre><code>#!/usr/bin/env python
  
  def get_match():
    cache=[]
    def match(v):
      if cache:
        return cache
      cache=[v]
      return cache
    return match
  m = get_match()
  m(1)
  </code></pre>
  
  <p>if I run it, it says:</p>
  
  <pre><code>UnboundLocalError: local variable 'cache' referenced before assignment
  </code></pre>
  
  <p>but if I do this:</p>
  
  <pre><code>#!/usr/bin/env python
  
  def get():
    y = 1
    def m(v):
      return y + v
    return m
  
  a=get()
  a(1)
  </code></pre>
  
  <p>it runs.</p>
  
  <p>Is there something with list? or my code organizing is wrong?</p>