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:
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)
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.
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.