break out of list comprehension?
<p>I am taking in an integer value, finding the factorial of that value and trying to count the number of trailing zeros if any are present. For example:</p>

<pre><code>def zeros(n):
    import math
    factorial = str(math.factorial(n))
    zeros_lst = [number if number == "0" (else) for number in factorial[::-1]]
    return len(zeros_lst)
</code></pre>

<p>The "else" in parenthesis is where the issue is occurring. I want to leave the loop if the as soon as it encounters a number that is not zero. I tried using break like you normally would, then looking up some examples but found nothing of similarity. </p>

<p>If someone knows how to break from a list comprehension or if is even possible that would be great. I am sure there are better ways to solve this problem, please post if you do. </p>

<p>There is a more mathematical approach to this problem that is very simple and easy to implement. We only need to count how many factors of ten there are in factorial(n). We have an excess of factors of 2, so we choose to count factors of 5. It doesn't look as clean, but it avoids the computation of a factorial. The algorithm accounts for extra factors of 5 that show up in numbers like 25, 50, 125 and all of the rest.</p>

<pre><code>def find_zeros_in_factorial(n):
    factors_of_5 = [n/5]
    while factors_of_5[-1] &gt; 0:
        factors_of_5.append(factors_of_5[-1]/5)
    return sum(factors_of_5)
</code></pre>

python list-comprehension break