title: Local Variable Referenced before Assignment - Python
body: <pre><code>x = 2
  y = 3
  
  mylist = [ [x,y] for x in range(x+1) for y in range(y+1)]
  
  print(mylist) 
  </code></pre>
  <blockquote>
  <p>UnboundLocalError                         Traceback (most recent call
  last)  in 
  3
  4
  ----&gt; 5 mylist = [ [x,y] for x in range(x+1) for y in range(y+1)]
  6
  7 print(mylist)</p>
  <p> in (.0)
  3
  4
  ----&gt; 5 mylist = [ [x,y] for x in range(x+1) for y in range(y+1)]
  6
  7 print(mylist)</p>
  <p>UnboundLocalError: local variable 'y' referenced before assignment</p>
  </blockquote>
  <p>I do not understand what is wrong here and how to correct it.</p>