I have a function prime_factorizethat returns dictionary matching from simple dividers to its credentials. For example, 50 = 2 ^ 1 * 5 ^ 2, therefore prime_factorize(50)returns {2 : 1, 5 : 2}.
Assuming this is documented behavior, what would be the least surprising way to report an error if it is caused by 0, 1, or a negative number? Give up ValueError? Return what looks like the correct output (e.g. prime_factorize(-5) -> {-1: 1, 5: 1})? return empty dict?
And if you have a better format for returning simple factorization, I would also like to hear that.
source
share