擅长:python、mysql、java
<p>最好的方法是根本不显式循环。救援工具:</p>
<pre><code>from itertools import takewhile
it = ((x, f(x)) for x in range(50)) # first you define the resulting view
it = takewhile(lambda y: y[1] != 0, it) # define when to stop iterating
list(map(print, it)) # if you want to print it
</code></pre>
<p>+比循环快得多</p>