Created
February 7, 2021 18:53
-
-
Save vlad-bezden/183a0cb66a17da0162f7c053d9851e26 to your computer and use it in GitHub Desktop.
Prime factors of the number using recursion and walrus operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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