Created
September 13, 2012 13:05
-
-
Save fanzeyi/3714157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = [lambda: x for x in range(10)] | |
print x[0]() | |
''' | |
俺的第一反应是 x = [lambda: 1, lambda: 2, ...] | |
但是实际上是 x = [lambda x, lambda x], 所以返回的应该是这个 lambda list | |
''' | |
x = (lambda: x for x in range(10)) | |
print x.next()() | |
''' | |
(for .. in ) 语句返回一个迭代器.. 俺想当然的认为返回的是个 tuple 了…… | |
实际上感觉应该是 | |
for x in range(10): | |
yield lambda: x | |
的同义写法.. 所以这里返回的是 0 | |
''' | |
print [lambda: x for x in range(10)][0]() | |
''' | |
这个是最简单的.. 等同于 | |
for x in range(10): | |
pass | |
print x | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment