Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Created February 7, 2021 18:53
Show Gist options
  • Save vlad-bezden/183a0cb66a17da0162f7c053d9851e26 to your computer and use it in GitHub Desktop.
Save vlad-bezden/183a0cb66a17da0162f7c053d9851e26 to your computer and use it in GitHub Desktop.
Prime factors of the number 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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment