How does this function work?

exarkun at divmod.com exarkun at divmod.com
Mon Sep 20 15:44:20 EDT 2004


  >>> def f(y):
  ...     return [x for x in range(3), 1, y for y in range(4), 4]
  ... 
  >>> f(3)
  [[0, 1, 2], [0, 1, 2], 1, 1, 3, 3]
  >>> 

  I've been staring at it for 15 minutes and I'm no closer to understanding than when I started.

  Why is this even legal Python syntax?  What is going on that makes it return what it does?

  Jp



More information about the Python-list mailing list