prime_factors.py

1
2
3
4
5
6
7
def prime_factors(n):
    def _gen(n):
        p = next(filter(lambda p: n % p == 0, range(2, n+1)))
        yield p
        yield from _gen(n // p)

    return list(_gen(n))

Comments

Generator version for fun.

helenst commented 9 April 2016 at 15:41 UTC

You're not logged in right now. Please login via GitHub to comment