Quantcast
Channel: Sieve of Eratosthenes - Finding Primes Python - Stack Overflow
Viewing all articles
Browse latest Browse all 28

Answer by Vlad Bezden for Sieve of Eratosthenes - Finding Primes Python

$
0
0

Using recursion and walrus operator:

def prime_factors(n):    for i in range(2, int(n ** 0.5) + 1):        if (q_r := divmod(n, i))[1] == 0:            return [i] + factor_list(q_r[0])    return [n]

Viewing all articles
Browse latest Browse all 28

Trending Articles