擅长:python、mysql、java
<p>扩展fourtheye的答案;在迭代map函数之前,不会对map函数中的表达式求值。这个例子应该很清楚:</p>
<pre><code>from time import sleep
def badass_heavy_function():
sleep(3600)
# Method call isn't evaluated
foo = map(lambda x: x(), [badass_heavy_function, badass_heavy_function])
# Methods call will be evaluated, please wait 2 hours
bar = list(map(lambda x: x(), [badass_heavy_function, badass_heavy_function]))
for _ in foo:
# Please wait one hour
pass
</code></pre>