所以,我正在修改列表理解,以下让我感到惊讶:
>>> funs = [lambda x:x**i for i in range(10)]
>>> print [fun(2) for fun in funs]
[512, 512, 512, 512, 512, 512, 512, 512, 512, 512]
我将如何获得:
>>> funs2 = [lambda x:x**0, lambda x:x**1, lambda x:x**2, lambda x:x**3,
lambda x:x**4, lambda x:x**5, lambda x:x**6, lambda x:x**7,
lambda x:x**8, lambda x:x**9]
>>> print [fun(2) for fun in funs2]
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
有了列表推导,假设这样的事情是可能的吗?